Tkinter 返回条目的".!entry"而不是文本内容



我正在编写一个程序,该程序接受和输入并返回tkinter和tkintergrid,但是当我试图获得Entry中的值时,它不起作用!

我在网上寻找解决方案,但其中没有一个包括grid除了这个:
返回值的Tkinter文本输入,关闭GUI,但它的方式太难了!

下面是我的代码:
# import tkinter module
from tkinter import *
from tkinter.ttk import *
# creating main tkinter window/toplevel
master = Tk()
# this will create a label widget
l1 = Label(master, text = "First:")
l2 = Label(master, text = "Second:")
# entry widgets, used to take entry from user
e1 = Entry(master)
e2 = Entry(master)
def input_():
title = e1.get()
body = e2.get()
print(e1)
print(e2)
# grid method to arrange labels in respective
# rows and columns as specified
l1.grid(row = 0, column = 0, sticky = W, pady = 2)
l2.grid(row = 1, column = 0, sticky = W, pady = 2)
submit = Button(master, text="Submit", command=input_)
# this will arrange entry widgets
e1.grid(row = 0, column = 1, pady = 2)
e2.grid(row = 1, column = 1, pady = 2)
submit.grid(row = 3, column = 1, pady = 2)
# infinite loop which can be terminated by keyboard
# or mouse interrupt
mainloop()

这可能是因为在input函数中,您正在打印

print(e1)
print(e2)

Entry对象。您可能一直在尝试打印正在提取但未使用的titlebody

最新更新