[問題] 請問有人可以幫我看一下Tkinter嗎???謝謝!!
我這寫出來,不管按哪一個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()
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.241.220.100
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1399007855.A.BF4.html
→
05/02 13:42, , 1F
05/02 13:42, 1F
→
05/02 13:47, , 2F
05/02 13:47, 2F
→
05/02 13:47, , 3F
05/02 13:47, 3F
→
05/02 14:00, , 4F
05/02 14:00, 4F
→
05/02 14:01, , 5F
05/02 14:01, 5F
→
05/02 14:07, , 6F
05/02 14:07, 6F
→
05/02 14:10, , 7F
05/02 14:10, 7F
→
05/02 14:11, , 8F
05/02 14:11, 8F
→
05/02 14:25, , 9F
05/02 14:25, 9F
→
05/02 14:26, , 10F
05/02 14:26, 10F
推
05/02 16:33, , 11F
05/02 16:33, 11F
→
05/02 16:35, , 12F
05/02 16:35, 12F
→
05/02 19:05, , 13F
05/02 19:05, 13F
→
05/02 19:05, , 14F
05/02 19:05, 14F
→
05/02 19:30, , 15F
05/02 19:30, 15F
→
05/02 19:31, , 16F
05/02 19:31, 16F
→
05/02 19:46, , 17F
05/02 19:46, 17F
推
05/02 20:08, , 18F
05/02 20:08, 18F
→
05/02 20:09, , 19F
05/02 20:09, 19F
→
05/02 20:11, , 20F
05/02 20:11, 20F
→
05/02 20:12, , 21F
05/02 20:12, 21F
→
05/02 20:55, , 22F
05/02 20:55, 22F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):