Tkinter 返回“.!entry”而不是条目的文本内容
Tkinter returning ".!entry" instead of text contents of the Entry
我正在制作一个程序,它使用 tkinter 和 tkinter grid
获取和 returns 它,但是当我试图获取 Entry
中的值时,没用!
我在互联网上寻找解决方案,但 none 其中包括一个 grid
除了这个:
Return values of Tkinter text entry, close 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
个对象。您可能一直在尝试打印正在提取但未使用的 title
和 body
。
我正在制作一个程序,它使用 tkinter 和 tkinter grid
获取和 returns 它,但是当我试图获取 Entry
中的值时,没用!
我在互联网上寻找解决方案,但 none 其中包括一个 grid
除了这个:
Return values of Tkinter text entry, close 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
个对象。您可能一直在尝试打印正在提取但未使用的 title
和 body
。