menator01
Silver Coder
Changes background color every 3 seconds
Python:
from dataclasses import dataclass, astuple
import tkinter as tk
from random import randint
@dataclass
class RGB:
__slots__ = ['r','g','b']
r: int
g: int
b: int
def __str__(self):
return f'#%02x%02x%02x'.upper() % astuple(self)
def color(arg, arg2):
atup = [randint(0,255) for i in range(3)]
atup = tuple(atup)
colors = RGB(*atup)
arg['text'] = f'Color: {colors}'
arg2['bg'] = colors
root.after(3000, lambda: color(arg, arg2))
root = tk.Tk()
root.geometry('400x400+300+300')
colors = RGB(22,50,23)
label = tk.Label(root, font=(None, 28, 'normal'))
label['text'] = f'Color: {colors}'
label.pack(side='top')
bgcolor = tk.Label(root, bg=colors, relief='sunken')
bgcolor.pack(side='top', expand=True, fill='both', padx=5, pady=3)
root.after(3000, lambda: color(label, bgcolor))
root.mainloop()
Last edited: