tkinter返回。!而不是条目的文字内容
我正在制作一个程序,并使用tkinter和tkinter grid
将其返回,但是当我尝试获取entry> entry
中的值时'工作!
我在互联网上查找了解决方案,但其中没有一个包括网格
除此之外:
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()
I was making a program that takes and entry and returns it with tkinter and a tkinter grid
, but when I tried to get the value of what was in the Entry
, it didn't work!
I looked on the internet for solutions but none of them included a grid
except this one:
Return values of Tkinter text entry, close GUI, but it's way too hard!
Here is my code so far:
# 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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为在
输入
函数中,您正在打印entry
对象。您可能一直在尝试打印title
和body
,这些被提取但未使用。That's probably because in the
input
function, you are printingwhich are the
Entry
objects. You might have been trying to print thetitle
andbody
, which are being extracted, but unused.