【发布时间】:2020-05-17 20:48:19
【问题描述】:
好的,基本的故事。我创建了一个条目。引入文本后,您必须单击按钮将输入的文本存储到稍后打印的变量中。 代码如下:
from Tkinter import *
def myClick(entry_name, var):#defines function to get input from entry and store into var
var = entry_name.get()
root = Tk()#creates initial tk
lbl1 = Label(root, text = "hello")#before entry label
lbl1.grid(row = 0, column = 0)#label griding
ent = Entry(root, width = 15)# the entry
ent.grid(row = 1, column = 0)#entry gridding
hello = None #variable to store entry input
bt1 = Button(root, command = myClick(ent, hello))#button 1 creation and function attribution
bt1.grid(row = 3, column = 0)#button 1 griding
root.mainloop()
print(hello)
我很不清楚为什么该函数没有从条目中获取输入。
【问题讨论】:
标签: python python-3.x tkinter tkinter-entry