如何获取TextEntry输入文本tkinter

时间:2017-01-29 23:07:25

标签: python python-3.x tkinter get textbox

我正在使用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()

1 个答案:

答案 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()