我有一個Tkinter的類:創建的Tkinter類,並等待一個返回值
class DBCreatorWin():
def closeWindow(self):
tkMessageBox.showinfo("Ilmiont SQLite Database Manager", "This window cannot be closed.\nEnter a database name and press Continue.")
def returnName(self):
dbName = self.entry.get()
self.window.destroy()
return dbName
def __init__(self):
self.window = Toplevel()
self.window.transient(tkRoot)
self.window.grab_set()
self.window.resizable(width=False, height=False)
self.window.title("Ilmiont SQLite Database Manager")
self.window.protocol("WM_DELETE_WINDOW", self.closeWindow)
self.label = Label(self.window, text="Enter the name of the database to be created: ")
self.entry = Entry(self.window, width=30)
self.button = Button(self.window, text="Continue", command=self.returnName)
self.label.grid(row=0, column=0)
self.entry.grid(row=0, column=1)
self.button.grid(row=1, column=0, columnspan=2)
我想我的主要代碼中創建這個類的一個實例,並等待返回值。用戶在輸入字段中輸入名稱並按下繼續按鈕。此時,該值應該返回到類最初實例化的地方。我如何去做這件事?我似乎無法以正常的方式使其工作,並且對tkinter是新的。
由於提前, Ilmiont
調用'mainloop'直到窗口關閉後,代碼的正常流程將不會繼續。如果您希望GUI保持打開狀態,則必須從GUI內調用代碼邏輯。沒有[minimal example](http://stackoverflow.com/help/mcve),很難說你現在做錯了什麼。 – jonrsharpe
聽起來像你可能想使用類似['easygui'](http://easygui.sourceforge.net/)模塊的東西,而不是事件驅動。 – martineau