我正在使用tkinter。我有一个TextBox条目,但我不知道如何获取输入的文本。
我的代码是:
from tkinter import *
def th():
a = text.get()
print(a)
root = Tk()
text = Text(root)
text.pack()
btn = Button(root, text='hello', command=th())
root.mainloop()
答案 0 :(得分:0)
命令是:text.get("1.0", END)
在上下文中:
from tkinter import *
def th():
a = text.get("1.0", END)
print(a)
root = Tk()
text = Text(root)
text.pack()
btn = Button(root, text='hello', command=th) #don't need () for command, or use lambda: th()
btn.pack() #you forgot to pack your button.
root.mainloop()