【发布时间】:2017-06-07 14:39:37
【问题描述】:
我的任务是在 Tkinter 上创建一个标签和按钮。按钮必须更改标签,我必须更改按钮和标签的颜色。我已经改变了背景的颜色,但我不知道如何为标签和按钮做同样的事情。
from tkinter import *
from tkinter import ttk
def change():
print("change functon called")
def main():
rootWindow = Tk()
rootWindow.geometry('400x400')
rootWindow.configure(bg="red")
global Label
label = ttk.Label( rootWindow, text="Hello World!" )
label.pack()
button1 = ttk.Button( rootWindow, text="Change Label",
command=change)
button1.pack()
rootWindow.mainloop()
main()
【问题讨论】:
-
你知道你使用的是ttk标签还是tkinter标签吗?您是否阅读过小部件的文档?你搜索过这个网站吗?更改按钮属性有很多问题。