有问题的部分是我要求用户输入一个类, 我希望使用从另一个类中的该条目获得的值, 但是,无论如何,此代码总是给我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的副本。 –