【发布时间】:2012-02-20 03:10:53
【问题描述】:
我一直在试验 Tkinter,我有一个设置,我有一个输入框,然后在它下面有两个按钮(关闭和确定)。单击关闭时,框架被销毁。我希望它返回当时输入框中的任何内容,然后销毁框架。我只是不知道如何做到这一点。
这是我所拥有的一部分(f 是我的框架):
class App:
def DoThis(self):
#Earlier code that's not related to the question
v=StringVar()
e=Entry(f,textvariable=v)
buttonA=Button(f,text="Cancel",command=root.destroy)
buttonB=Button(f,text="OK")
另外,请注意,我想将字符串返回给调用函数,而不是立即打印。
我想要:
print App().DoThis() #to print what was in the entry box
#at the time of OK being clicked
【问题讨论】:
-
"return" 在事件驱动程序的上下文中没有意义。您希望将 tne 值返回到哪里?
-
我添加了更多代码,希望能消除您的困惑。
标签: python button tkinter tkinter-entry