创建一个文本框和一个按钮,当文本框失去焦点、在文本框中按回车键或单击按时显示文本框的内容。
from tkinter import *
win = Tk()
win.title('第四题')
win.geometry("500x250")
def callbutton():
print(e.get())
def callbutton1(entry):
print(e.get())
def press(entry):
print(entry.char,end=' ')
#将一字符串与Entry的值绑定
e = StringVar()
entry = Entry(win,textvariable = e)
#输出键盘事件每个字符串
entry.bind("<KeyPress>",press)
#按钮事件
b = Button(win,text = '获取Entry组件的内容',command = callbutton,width = 20)
#回车事件
entry.bind("<Return>",callbutton1)
# e.set('python')
entry.pack()
b.pack()
win.mainloop()