get()返回{}

2024-09-27 00:12:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从文本框中创建一个变量,但是当我显示条目时,它只显示“youentered{}”

我已经导入了所有需要导入的内容,并且在OS10.9上运行了Python2.7

def beenclicked():
    tkMessageBox.showinfo("You entered"+petals.get()) 


gui=Tk()
gui.title("Flower Creator")

label1= Label(gui, text="Number of petals:")
label1.pack(side='top',pady=10)

petals = Entry(gui)
petals.pack(side='top')

button1 = Button(gui, text="Generate flower", width=20, command=beenclicked) 
button1.pack(side='bottom',pady=15,padx=15)




gui.mainloop()

Tags: text内容topdef条目guisidepack
1条回答
网友
1楼 · 发布于 2024-09-27 00:12:54

^{}的第一个参数是标题。试着这样做:

tkMessageBox.showinfo("You entered:", petals.get())

您可能没有看到用户的输入,因为它在对话框窗口的标题中,并且窗口不会自动缩放以适应标题。对话框内容为空,因为您只提供了标题。你知道吗

相关问题 更多 >

    热门问题