Button action to set Button background : Button « GUI Tk « Python






Button action to set Button background

Button action to set Button background

from Tkinter import *

class App:
    def __init__(self, master):

        frame = Frame(master)
        frame.pack()

        self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
        self.button.pack(side=LEFT)

        self.hi_there = Button(frame, text="Hello", command=self.say_hi)
        self.hi_there.pack(side=LEFT)

    def say_hi(self):
    if self.hi_there["background"] == "green":  
      self.hi_there["background"] = "yellow"
    else:
      self.hi_there["background"] = "green"

root = Tk()

app = App(root)

root.mainloop()

           
       








Related examples in the same category

1.Add a button to frameAdd a button to frame
2.Simple Button ActionSimple Button Action
3.Disable a buttonDisable a button
4.Enable a buttonEnable a button
5.Set Button to get focusSet Button to get focus
6.Button Border stylesButton Border styles
7.Button event binding: without passing the event as an argument Button event binding: without passing the event as an argument
8.Button focusButton focus
9.create a button, and put it into a Containercreate a button, and put it into a Container
10.Set Button background by property nameSet Button background by property name
11.Specify the button's propertiesSpecify the button's properties
12.Button action inside a classButton action inside a class
13.Button widthButton width
14.Buttons on a toolbarButtons on a toolbar
15.Button foreground colorButton foreground color
16.Creating buttonsCreating buttons
17.Button single click and double clickButton single click and double click
18.Use lambda to generate a call back function for a buttonUse lambda to generate a call back function for a button
19.adds user-defined callbacks as button actionadds user-defined callbacks as button action
20.Subclasses buttonSubclasses button
21.Subclass HelloButton: redefine press-handler methodSubclass HelloButton: redefine press-handler method
22.Sub class button: add callback method and pack myselfSub class button: add callback method and pack myself
23.Sub class button: add callback method and use a dictionarySub class button: add callback method and use a dictionary
24.Button BorderButton Border
25.Button border size Button border size
26.Button border effects: RAISEDButton border effects: RAISED
27.Button background, foreground and fontButton background, foreground and font
28.Button width and heightButton width and height
29.Config button propertiesConfig button properties
30.Add gif image to a buttonAdd gif image to a button
31.Bind mouse single click and double click to a buttonBind mouse single click and double click to a button