Python Forum

Full Version: changing the frame colour
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to change the background of a frame using four colour buttons placed at four corners of the frame.
I was trying by adding only one button in the frame and changing the color when button is pressed but its not changing the color when the button is in the frame and works when the button is in the window.
import tkinter as tk

root = tk.Tk()
root.geometry("100x100")
frame = tk.Frame(root, height=100, width=100)


def change_bg():
    frame.config(background='red')
    

button = tk.Button(frame, text="Paint",command=change_bg)


button.pack()
frame.pack()
root.mainloop()
Hi nick123

Now it should work:
import tkinter as tk
 
root = tk.Tk()
root.geometry("100x100")
frame = tk.Frame(root, height=100, width=100)
 
 
def change_bg():
    frame.config(background='red')
     
 
button = tk.Button(frame, text="Paint",command=change_bg)
 
 
button.pack()
frame.pack(fill='both', expand=True)
root.mainloop()
wuf :-)
It worked ! Thank You wuf!