我正在尝试制作一个程序,当我在条目中写入内容并单击按钮时,它会锁定(“hello”+我在条目中输入的内容)。当我没有在变量中创建它时,以及当我在变量中创建它并且变量在函数中时,它都能工作,但当我在变量中创建它时,它不起作用,但我在任何函数中都没有创建它
from tkinter import *
root = Tk()
root.title("Problems")
root.geometry("1080x720")
root.config(bg="blue")
entry = Entry(root,bg="purple",fg="black")
entry.pack()
Hello = "Hello " + entry.get() + "!"
def click():
myLabel = Label(root, text = Hello)
myLabel.pack()
Button = Button(root,text="enter your name",command=click,bg="Black",fg="white")
Button.pack()
root.mainloop()
您正在定义Hello变量,然后用户才能输入条目。 你必须这样做:
编辑:避免过度命名变量
就像你写的:
Button = Button(...)
现在,如果您尝试创建一个新按钮,您将得到一个错误相关问题 更多 >
编程相关推荐