-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (32 loc) · 938 Bytes
/
Copy pathmain.py
File metadata and controls
47 lines (32 loc) · 938 Bytes
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
# date: 2019.04.09
#
import tkinter as tk
# --- functions ---
def get_text(text):
print(text)
def get_widget(widget):
print(widget["text"])
widget["text"] = "DONE"
widget["bg"] = "green"
def get_event(event):
print(event.widget["text"])
event.widget["text"] = "DONE"
event.widget["bg"] = "green"
# --- main ---
list_words = ("One", "Two", "Three")
root = tk.Tk()
# access button's text in function assigned to button
for word in list_words:
btn = tk.Button(root, text=word, command=lambda txt=word:get_text(txt))
btn.pack()
# access button in function assigned to button
for word in list_words:
btn = tk.Button(root, text=word)
btn["command"] = lambda widget=btn:get_widget(widget)
btn.pack()
# access button in function assigned to button
for word in list_words:
btn = tk.Button(root, text=word)
btn.bind('<Button-1>', get_event)
btn.pack()
root.mainloop()