1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import tkinter as tk
class color_button:
def __init__(self):
self.tag = None
def widgets_selected(self,widget1,widget2):#widget is the selected
self.disable(widget2)
if widget1['text']=='yes':
self.colorize(widget1,"green")
else :
self.colorize(widget1,"red")
return
def disable(self,widget):
widget['state']='disabled'
return
def colorize(self,widget,color):
widget['bg']=color
return
react_button=color_button()
def action():
react_button.widgets_selected(bouton1,bouton2)
Question2=tk.Label(root,text="Quit ?").grid(row=2,column=0)
bouton3=tk.Button(root,text='yes',command=root.destroy).grid(row=3,column=0)
bouton4=tk.Button(root,text='no').grid(row=3,column=1)
def action2():
react_button.widgets_selected(bouton2,bouton1)
Question2=tk.Label(root,text="Quit ?").grid(row=2,column=0)
bouton3=tk.Button(root,text='yes',command=root.destroy).grid(row=3,column=0)
bouton4=tk.Button(root,text='no').grid(row=3,column=1)
root=tk.Tk()
Question1=tk.Label(root,text='Ca va ?').grid(row=0,column=0)
bouton1=tk.Button(root,text='yes',command=action)
bouton1.grid(row=1,column=0)
bouton2=tk.Button(root,text='no',command=action2)
bouton2.grid(row=1,column=1)
root.mainloop() |
Partager