简体   繁体   中英

| 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)

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM