python - 文本小部件 tkinter

标签 python tkinter

我遇到了一点问题。我有一个用于用户输入的文本小部件而不是输入小部件,并且似乎无法从中获取数据。例如,对于条目小部件,您可以使用 .get(),但是对于文本小部件您会使用什么?

感谢您的帮助...

Label(insertscreen, text="Please enter the Recipe ID").grid(row=0, sticky=W)
Label(insertscreen, text="Please enter the Recipe Name").grid(row=1, sticky=W)
Label(insertscreen, text="Please enter the Method of the Recipe").grid(row=2, sticky=W)
Label(insertscreen, text="Please enter the First Ingredient").grid(row=3, sticky=W)
Label(insertscreen, text="Please enter the Second Ingredient").grid(row=4, sticky=W)
Label(insertscreen, text="Please enter the Third Ingredient").grid(row=5, sticky=W)
Label(insertscreen, text="Please enter the Fourth Ingredient").grid(row=6, sticky=W)
Label(insertscreen, text="Please enter the Fifth Ingredient").grid(row=7, sticky=W)
Label(insertscreen, text="Please enter the Cooking Time, in minutes").grid(row=8, sticky=W)

Enter1= Entry(insertscreen)
Enter1.grid(row=0, column=1)
Enter2= Entry(insertscreen)
Enter2.grid(row=1, column=1)
Enter3= Text(insertscreen, width = 50, height = 10)
Enter3.grid(row=2, column=1)
Enter4= Entry(insertscreen)
Enter4.grid(row=3, column=1)
Enter5= Entry(insertscreen)
Enter5.grid(row=4, column=1)
Enter6= Entry(insertscreen)
Enter6.grid(row=5, column=1)
Enter7= Entry(insertscreen)
Enter7.grid(row=6, column=1)
Enter8= Entry(insertscreen)
Enter8.grid(row=7, column=1)
Enter9= Entry(insertscreen)
Enter9.grid(row=8, column=1)

#Entering the new recipe into the database
def submit_recipe():

global Enter1, Enter2, Enter3, Enter4, Enter5, Enter6, Enter7, Enter8, Enter9, new_db

ID = Enter1.get()
Name = Enter2.get()
Method = Enter3.get()
Ing1 = Enter4.get()
Ing2 = Enter5.get()
Ing3 = Enter6.get()
Ing4 = Enter7.get()
Ing5 = Enter8.get()
TimeofRec = Enter9.get()

最佳答案

文本小部件使​​用 get,但由于该小部件管理多行文本,因此它具有选择器来指定内容区域。请参阅tkdocs有关使用此小部件和 manual page 的教程的站点了解完整详情。获取第一行文本的示例:

firstline = textWidget.get("1.0", "1.0 lineend")

关于python - 文本小部件 tkinter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784352/

相关文章:

python - 如何使用回车键调用按钮命令

python - 如何让 for 循环在 python 2.7 中与 tkinter 一起工作?

python - 如何让脚本等待用户在 Tkinter 中交互?

python - 如何在 Tkinter 中将形状变成按钮

widget - 如何在 Tkinter 中获取 Master Frame 的名称

python 日历小部件 - 返回用户选择的日期

Python:如何使用 feedparser 和 etags 检查 RSS 更新

python - 如何在 Dataframe 中删除最后一个不是 NaN 的值?

python oracle SQL查询转换

python - 为什么此代码没有删除行? (Flask-SQLAlchemy)