python tkinter使用Entry做为文本框输入,通过textvariable绑定数据给文本框,然后中使用get函数获取内容。如果想要Enter获取内容,则需要绑定
from tkinter import *
def rtnkey(event=None):
print(e.get())
root = Tk()
e = StringVar()
entry = Entry(root, validate='key', textvariable=e, width=50)
entry.pack()
entry.bind('
root.title('测试回车获取文本框内容')
root.mainloop()
效果如下:
您好,我想到了这个方法:
# coding : utf-8
from tkinter import *
root = Tk()
last_text = ''
def text_change(event):
global last_text
got = text.get('1.0', 'end')
if got != last_text:
last_text = got
print('文本被修改了')
text = Text(root)
text.bind('', text_change)
text.grid()
root.mainloop()
不过还是有些问题,有时候会重复调用,比如输入一串中文时