TAGS :Viewed: 4 - Published at: a few seconds ago

[ How to update one element of a Tkinter GUI? ]

I have 2 functions, MakeGUI:

def makeGUI():

    #Define the global variables of the function.
    global root,f1,f2,f3,r,y,b,g,patColor

    #Initialize Gui Items.
    root = Tk()
    root.wm_title("Buttons")
    f3 = Frame(root)
    f1 = Frame(root)
    f2 = Frame(root)
    r = Button(f1, text= "Red", fg="Black", bg="Red", width=25, font="TimesNewRoman", bd=1)
    y = Button(f1, text= "Yellow", fg="Black", bg="Yellow", width=25, font="TimesNewRoman", bd=1)
    b = Button(f2, text= "Blue", fg="Black", bg="Blue", width=25, font="TimesNewRoman", bd=1, command=showPattern)
    g = Button(f2, text= "Green", fg="Black", bg="Green", width=25, font="TimesNewRoman", bd=1)
    patColor = Label(f3, bg="White", width=66)

    #Pack the GUI items so they will show.
    f3.pack()
    f1.pack()
    f2.pack()
    r.pack(side=LEFT)
    y.pack(side=RIGHT)
    b.pack(side=LEFT)
    g.pack(side=RIGHT)
    patColor.pack()

    #Show the GUI.
    root.mainloop()

And showPattern:

def showPattern():
    patColor.bg = "Blue"

Is there any way to update only the patColor bg property without refreshing the whole GUI? I am making a simon says type game with python 2.7 and i need it to cycle through a pattern array.

Answer 1


I've discovered after looking into more that the proper notation is:

patColor["bg"] = "Color"