有問題的部分是我要求用戶輸入一個類, 我希望使用從另一個類中的該條目獲得的值, 但是,無論如何,此代碼總是給我0已進入。 我認爲這可能是因爲當另一個類被執行時,存儲在前一個類的入口中的值消失。但我不知道如何去解決它。 任何編碼大師能幫我一點點嗎?如何將Tkinter中的某個條目的值傳遞給另一個類?
......
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
BackButton = tk.Button(self, text="Back",font=TNR24,command=lambda: controller.show_frame(MainPage))
PrintButton = tk.Button(self, text="Print it", command=self.print_message)
ExitButton = tk.Button(self,text="EXIT",command=exit_window)
ProceedButton=tk.Button(self, text="Proceed", command=lambda: controller.show_frame(PageTwo))
self.NumOfVertices= tk.IntVar()
global VertexNumber
VertexNumber=self.NumOfVertices.get()
NumOfVerticesEntry=tk.Entry(self,textvariable=self.NumOfVertices)
ProceedButton.pack()
BackButton.pack()
ExitButton.place(x=1240, y=670, width=40, height=30)
PrintButton.pack()
NumOfVerticesEntry.pack()
def print_message(self):
print self.NumOfVertices.get()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
lable=tk.Label(self,text=VertexNumber)
......
代碼很長,所以我只拿了我需要幫助的部分。 VertexNumber是我想要在類Pagetwo中存儲和使用的變量。 但無論我輸入什麼,它總是變爲0。 用戶輸入後是否有任何方法可以永久保存該變量?
此問題是http://stackoverflow.com/q/32212408/7432的副本。 –