[英]| Python - Tkinter | Changing the color of differente widget on button click
What I want : When the user press a button (Pink Skin) all the current color will switch to an other. 我想要的是:当用户按下按钮(粉红色皮肤)时,所有当前颜色将切换为其他颜色。 But when its time to do the switch of color the color don't change on the screen.
但是,当需要进行颜色切换时,屏幕上的颜色不会改变。 But if I add a print after (Pink skin is loaded) with the new color it send the new one.
但是,如果我在加载了新的颜色(粉红色的皮肤)后添加了打印件,它将发送新的颜色。 But the old one is still use for my widget and frame.
但是旧的仍然用于我的小部件和框架。 (example: When I use color for a bg I used colorBg who's a variable with the #color etc)
(示例:当我将颜色用于bg时,我使用了colorBg,后者是#color等变量)
I also get no error, everything else is working fine. 我也没有任何错误,其他所有工作都很好。
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")
Simply call the label.config()
function. 只需调用
label.config()
函数。
Something like this: 像这样:
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.