gpt4 book ai didi

python - 当我在 tkinter 中使用条目时,我得到空字符串

转载 作者:行者123 更新时间:2023-12-01 00:41:49 26 4
gpt4 key购买 nike

我尝试使用条目将文件路径添加到我的应用程序,但每次该条目都返回空字符串

def command1(event):
if entry1.get() == 'localhost' and entry2.get() == 'amine' and entry3.get()=='aze123qsd' and entry4.get()=='GTFS':
top = Toplevel()
top.title("Add a file")
top.geometry("600x300")
text=Label(top ,text="Add the file path")
text.place(relx=0.3 ,rely=0.3)
entry=Entry(top)
entry.place(relx=0.5 ,rely=0.3)
paths=entry.get()
entry.bind('<Return>', commnad3)
button1 = Button(top, text="show the last window")
button1.place(relx=0.55 ,rely=0.7)
button2 =Button(top ,text="Use old data", command=old)
button2.place(relx=0.3 ,rely=0.7)

最佳答案

您的问题是由于您在对该条目执行 get() 的同时创建了该条目。此时您所拥有的只是一个空的输入字段。

您需要在将某些内容放入其中后获取该条目信息。

以这个例子为例,如果您有任何疑问,请告诉我。

import tkinter as tk


root = tk.Tk()


def print_entry(e):
print(e.get())


def command1():
top = tk.Toplevel()
entry = tk.Entry(top)
entry.pack()
tk.Button(top, text="Print Entry", command=lambda: print_entry(entry)).pack()


tk.Button(root, text="TOPLEVEL", command=command1).pack()

root.mainloop()

关于python - 当我在 tkinter 中使用条目时,我得到空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57291610/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com