我得到了一個「TypeError:'NoneType'對象不可調用的錯誤」 所以我已經爲我的GUI編寫了一些代碼,並且在選擇文件後我想要一個新頁面。頁面沒有顯示爲GUI python
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.quit_program()
self.browse_file()(self, text="Create new window",
command=self.create_window)
self.button.pack(side='top')
def create_window(self):
self.counter += 1
t = tk.Toplevel(self)
t.wm_title("Window #%s" % self.counter)
l = tk.Label(t, text="This is window #%s" % self.counter)
l.pack(side="top", fill="both", expand=True, padx=100, pady=100)
self.file_opt = options = {}
options['defaultextension'] = '.txt'
options['filetypes'] = [('musicfiles', '.mp3'),('videofiles','.mp4')]
options['parent'] = self
options['title'] = 'This is a title'
def quit_program(self):
self.quitButton = tk.Button(self, text='Quit',
command=self.quit)
self.quitButton.grid()
def browse_file(self):
self.browseButton = tk.Button(self, text='Browse',command=self.askopenfile)
self.browseButton.grid()
def askopenfile(self):
return tkFileDialog.askopenfile(**self.file_opt)
app = Application()
app.master.title('Sample application')
app.mainloop()
回溯是:
Traceback (most recent call last):
File "C:/Users/121794/Desktop/FYPtestGUI.py",
line 39, in <module> app = Application()
File "C:/Users/121794/Desktop/FYPtestGUI.py",
line 11, in init command=self.create_window)
TypeError: 'NoneType' object is not callable
請*總是*發佈完整的回溯。特別是在這種情況下,它會將您指向代碼中的失敗行。 – msvalkon
@msvalkon對不起,只是該網站不允許我上傳整個代碼 – user3817491
@msvalkon Traceback(最近呼叫最後): 文件「C:/Users/121794/Desktop/FYPtestGUI.py」,第39行,在 應用程式=應用程序() 文件 「C:/Users/121794/Desktop/FYPtestGUI.py」,第11行,在__init__ 命令= self.create_window) 類型錯誤: 'NoneType' 對象不是可調用 –
user3817491