【发布时间】:2020-05-16 20:17:40
【问题描述】:
好的,所以我一直在尝试从 Tkinter 的条目中获取用户输入并将其存储到在程序末尾打印的变量中,但是当打印变量时,输出是初始值。
代码:
from tkinter import *
hello = ''
root = Tk()
e = Entry(root, width = 50)
e.pack()
def myClick():
hello = e.get()
button1 = Button(root, text = 'ik', command = myClick)
button1.pack()
root.mainloop()
print(hello)
【问题讨论】:
-
hello函数myClick与全局变量hello不同。您可以在函数中使用global关键字。 -
我使用 global like: global.hello = e.get()?
标签: python tkinter tkinter-entry