如何从Tkinter文本框小工具获取输入?如何从Python 2.7.3中的文本框中获取Tkinter输入?
3 回答
呼如林
TA贡献1798条经验 获得超3个赞
要从文本框中获取Tkinter输入,必须向常规.get()函数添加更多属性。如果我们有一个文本框myText_Box,那么这是检索其输入的方法。
def retrieve_input():
input = self.myText_Box.get("1.0",END)第一部分,"1.0"意味着输入应该从第一行读取,字符为零(即:第一个字符)。END是导入的常量,设置为字符串"end"。该END部分意味着读取直到到达文本框的末尾。唯一的问题是它实际上为我们的输入添加了换行符。因此,为了解决它,我们应该END改为end-1c-1c删除1个字符,同时-2c意味着删除两个字符,依此类推。
def retrieve_input():
input = self.myText_Box.get("1.0",'end-1c')
UYOU
TA贡献1878条经验 获得超4个赞
这是我用python 3.5.2做的方式:
from tkinter import *root=Tk()def retrieve_input():
inputValue=textBox.get("1.0","end-1c")
print(inputValue)textBox=Text(root, height=2, width=10)textBox.pack()buttonCommit=Button(root, height=1, width=10, text="Commit",
command=lambda: retrieve_input())#command=lambda: retrieve_input() >>> just means do this when i press the buttonbuttonCommit.pack()mainloop()与此同时,当我在文本小部件中键入“blah blah”并按下按钮时,无论打字输出的是什么。所以我认为这是将用户输入从Text小部件存储到变量的答案。
添加回答
举报
0/150
提交
取消
