我可以使用 F5 從 Notepad++ 打開任何 python 文件,除非它引用具有相對路徑的圖像。必須有一種方法可以使 Notepad++ F5 的工作方式與在 Windows 資源管理器中雙擊文件名或右鍵單擊相同的文件名以“使用空閑編輯”相同。如何讓 Notepad++ 打開一個文件而不將它硬編碼到我的 .py 文件中,因為它存在于我的計算機上的完整路徑?我的應用程序的最終用戶不需要我計算機上的路徑。我找不到關于像我這樣的初學者如何修復 NPP 以正確執行此操作的說明。我在 Windows 7 上使用 NPP v7.4.2 32 位。我試過 NPP 論壇,但它的搜索引擎和谷歌都沒有找到答案。僅當我對完整路徑進行硬編碼時,F5 才能正確打開文件,如頂部未注釋的代碼行所示。我以為我在這里找到了答案,但是當我嘗試時看到下面的第二條錯誤消息img4 = tk.PhotoImage(file=os.path.abspath("joe.gif") , master=root)顯然,NPP 強加給我一條絕對路徑。感謝您的幫助。import tkinter as tkroot = tk.Tk()# img4 = tk.PhotoImage(file="joe.gif", master=root)img4 = tk.PhotoImage(file="c:/tkinter_code/joe.gif" , master=root)logoimage = tk.Label(root, image=img4)logoimage.image = img4logoimage.grid()root.mainloop()Traceback (most recent call last):File "C:\tkinter_code\how_to_get_npp_to_display_images_with_relative_path_tkinter.py", line 9, in <module> img4 = tk.PhotoImage(file="joe.gif", master=root) File "C:\Users\LUTHER\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 3393, in __init__Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Users\LUTHER\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__ init__.py", line 3349, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "joe.gif": no such file or directoryTraceback (most recent call last):File "C:\tkinter_code\how_to_get_npp_to_display_images_with_relative_path_tkinter.py", line 14, in <module> img4 = tk.PhotoImage(file=os.path.abspath("joe.gif") , master=root) File "C:\Users\LUTHER\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 3393, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Users\LUTHER\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 3349, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "C:\Program Files\Notepad++\joe.gif": no such file or directory
添加回答
舉報
0/150
提交
取消