Python 如何更新Tkinter GUI的一个元素?
我有两个函数,MakeGUI:Python 如何更新Tkinter GUI的一个元素?,python,python-2.7,tkinter,Python,Python 2.7,Tkinter,我有两个函数,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 = Fr
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()
和展示模式:
def showPattern():
patColor.bg = "Blue"
有没有办法只更新patColor bg属性而不刷新整个GUI?我正在用python 2.7制作一个simon says类型的游戏,我需要它在一个模式数组中循环。在深入研究之后,我发现正确的符号是:
patColor["bg"] = "Color"
可以在另一个标签上画一个新标签另一个正确的方法是
patColor.config(bg=“Color”)