更新时间:2022-12-19 15:50:38
操作:
message = 'Button Pressed'
不会影响标签小部件.要做的就是将全局变量message
重新分配给新值.
will not affect the label widget. All it will do is reassign the global variable message
to a new value.
要更改标签文本,可以使用其 .config()
方法(也称为.configure()
):
To change the label text, you can use its .config()
method (also named .configure()
):
def press():
Instruction.config(text='Button Pressed')
此外,创建标签时,您需要在单独的一行上调用pack
方法:
In addition, you will need to call the pack
method on a separate line when creating the label:
Instruction = tkinter.Label(Tk, text=message, font='size, 20')
Instruction.pack()
否则,会将Instruction
分配给None
,因为这是该方法的返回值.
Otherwise, Instruction
will be assigned to None
because that is the method's return value.