[英]| Python - Tkinter | Changing the color of differente widget on button click
我想要的是:當用戶按下按鈕(粉紅色皮膚)時,所有當前顏色將切換為其他顏色。 但是,當需要進行顏色切換時,屏幕上的顏色不會改變。 但是,如果我在加載了新的顏色(粉紅色的皮膚)后添加了打印件,它將發送新的顏色。 但是舊的仍然用於我的小部件和框架。 (示例:當我將顏色用於bg時,我使用了colorBg,后者是#color等變量)
我也沒有任何錯誤,其他所有工作都很好。
def skin(skinColor):
global colorButton,colorOver,colorBg
if skinColor == "default":
print("Default skin loaded")
elif skinColor == "blue":
print("Blue skin loaded")
elif skinColor == "pink":
colorButton.clear()
colorBg.clear()
colorButton = list("blue")
colorBg = list("white")
print("Pink skin loaded")
只需調用label.config()
函數。
像這樣:
import tkinter as tk
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
def fu():
button.config(bg='green')
button = tk.Button(frame, text="Change something", fg="red", command=fu)
button.pack()
root.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.