我没有在python中获得所需的输出

问题描述 投票:0回答:1
from tkinter import *

root = Tk()
root.title('printer')
label = Label(root, text = "WELCOME", fg = "grey")

label.pack()
textbox = Entry(root)
textbox.pack()


def whenclicked():
    global hello
    hello = "textbox.get()"
    label1 = Label(root, text = hello)
    label1.pack()



button = Button(root, text = "print it", command = whenclicked())
button.pack()
root.mainloop()

当我运行此代码时,在单击按钮之前,输出已经存在。这有什么问题?

python button tkinter
1个回答
0
投票

看来标签可能是mainloop的一部分,这可能导致它与其余代码分开工作,而没有交互,将其从mainloop中移出。

© www.soinside.com 2019 - 2024. All rights reserved.