[英]tkinter button text color is not changing
按鈕文本顏色在創建時為藍色,一旦單擊,按鈕文本顏色應根據代碼變為紅色。 但是點擊顏色並沒有改變
from tkinter import Button,Tk,Frame,DISABLED,Label
def on_click(button_id):
btn[button_id].configure(text='clicked',state=DISABLED,fg ="red")
window = Tk()
frame = Frame(window)
frame2 = Frame(window)
frame2.pack()
frame.pack()
btn=[]
lbl=Label(frame2,text="Hello there")
lbl.pack()
for i in range(0,5):
b=Button(frame,text="hello!!", fg="blue",font='sans 8 bold',command = lambda
button_id=i: on_click(button_id),width = 4, relief = "groove")
b.grid(row=i,column=0)
btn.append(b)
window.mainloop()
您需要從on_click
function 中刪除state=DISABLED
才能使這項工作
def on_click(button_id):
btn[button_id].configure(text='clicked', fg ="red")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.