Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] changing the frame colour
#1
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()
Quote
#2
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 :-)
Quote
#3
It worked ! Thank You wuf!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 2,695 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 2,569 Apr-18-2019, 05:36 PM
Last Post: atlass218
  Can't change the colour of Tk button text Pilover 4 3,836 Feb-27-2019, 09:02 PM
Last Post: Pilover
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 2,439 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)