-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton_change_bg.py
55 lines (42 loc) · 1.85 KB
/
button_change_bg.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from Tkinter import *
class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()
button_name = "OK"
# command binding
self.button1 = Button(self.myContainer1,
command=lambda
arg1=button_name, arg2=1, arg3="Good stuff!":
self.buttonHandler(arg1, arg2, arg3)
)
# event binding -- passing the event as an argument
self.button1.bind("<Return>",
lambda
event, arg1=button_name, arg2=1, arg3="Good stuff!":
self.buttonHandler_a(event, arg1, arg2, arg3)
)
self.button1.configure(text=button_name, background="green")
self.button1.pack(side=LEFT)
self.button1.focus_force() # Put keyboard focus on button1
button_name = "Cancel"
self.button2 = Button(self.myContainer1,
command=lambda
arg1=button_name, arg2=2, arg3="Bad stuff!":
self.buttonHandler(arg1, arg2, arg3)
)
self.button2.bind("<Return>",
lambda
event, arg1=button_name, arg2=2, arg3="Bad stuff!":
self.buttonHandler(arg1, arg2, arg3)
)
self.button2.configure(text=button_name, background="red")
self.button2.pack(side=LEFT)
def buttonHandler_a(self, event, argument1, argument2, argument3):
print
"buttonHandler_a received event", event
self.buttonHandler(argument1, argument2, argument3)
root = Tk()
myapp = MyApp(root)
root.mainloop()