Hi Guys,
Here I am trying to create a very simple function to change a Frame background color as by a btn event handling as following:

from Tkinter import *

class App:
   def __init__(self, parent):
    self.myParent = parent
    self.fm = Frame(parent)
    self.fm.pack()

    self.btnBlue = Button(self.fm, text = "Blue")
    self.btnBlue.bind("<Button-1>", self.make_blue)
    self.btnBlue.pack()

   def make_blue(self, event):
    self.fm = Frame(self.fm, bg="blue").pack()

root = Tk()
root.title ("Color Option")
app = App(root)
root.mainloop()

as you can see I have a button which is suppose to change the Frame's back ground color to BLUE but every time that I click on the button it just create a vertical thin line at bottom of the button and if you continue clicking it increase!
Can you please take a look at this code and let me know what I am doing wrong?

Thanks

Here is a solution

from Tkinter import *

class App:
   def __init__(self, parent):
    self.myParent = parent
    self.fm = Frame(parent, width=400, height=300)
    self.fm.pack_propagate(0) # to keep the frame size
    self.fm.pack()

    self.btnBlue = Button(self.fm, text = "Blue", command=self.make_blue)
    self.btnBlue.pack()

   def make_blue(self):
    # Don't create new widgets, configure existing ones
    self.fm.configure(bg="blue")

root = Tk()
root.title ("Color Option")
app = App(root)
root.mainloop()
commented: Good help +1

Gribouillis,
I appreciate your time and thanks for your clear and perfect reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.