我這寫出來,不管按哪一個button只會顯示橘色,有辦法讓它顯示相對應的顏色嗎??
from Tkinter import *
the_window = Tk()
the_window.title('ONE Button Colour')
start_color = 'grey'
label_bg = ['red', 'Green', 'Blue', 'Yellow', 'Orange']
button_color = ['Red', 'Green', 'Blue', 'Yellow', 'Orange']
label_colour = StringVar()
def change_colour():
if label_colour.get() == 'r':
colour['bg'] = 'red'
elif label_colour.get() == 'g':
colour['bg'] = 'green'
elif label_colour.get() == 'b':
colour['bg'] = 'blue'
elif label_colour.get() == 'y':
colour['bg'] = 'yellow'
else:
colour['bg'] = 'orange'
for r in range(5):
#for c in range(2):
colour = Label(the_window, bg = start_color, compound = 'bottom',
width = 8,height = 1)
colour.grid(row=r,column=0, padx = 2, pady = 3)
Button(the_window, text = button_color[r], command = change_colour,
width = 8,height = 1 ).grid(row=r,column=1, padx = 2, pady = 7)
the_window.mainloop()