May-06-2022, 07:33 PM
One more. Change background color with button click in tkinter.
import tkinter as tk from random import randint def rgb(label): color = tuple(randint(0, 255) for i in range(3)) label['bg'] = f'#%02x%02x%02x' % color root = tk.Tk() label = tk.Label(root, width=50, height=20, relief='groove') label.pack(padx=5, pady=4) button = tk.Button(root, text='change color', command=lambda:rgb(label)).pack(expand=True, fill='both', padx=5, pady=4) root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags