tkinter返回。!而不是条目的文字内容

发布于 2025-01-24 08:00:41 字数 1258 浏览 1 评论 0原文

我正在制作一个程序,并使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星軌x 2025-01-31 08:00:41

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

print(e1)
print(e2)

entry对象。您可能一直在尝试打印titlebody,这些被提取但未使用。

That's probably because in the input function, you are printing

print(e1)
print(e2)

which are the Entry objects. You might have been trying to print the title and body, which are being extracted, but unused.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文