Skip to content

Commit d340d3d

Browse files
authored
Library: Port 'Toggle Button' to Python (#731)
1 parent 1da6c6d commit d340d3d

File tree

1 file changed

+22
-0
lines changed
  • src/Library/demos/Toggle Button

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gtk
5+
import workbench
6+
7+
buttons = {
8+
"button_no_look": "Don't look",
9+
"button_look": "Look",
10+
"button_camera": "Camera",
11+
"button_flashlight": "Flashlight",
12+
"button_console": "Console",
13+
}
14+
15+
16+
def on_active(name):
17+
return lambda button, _: print(f'{name} {"On" if button.get_active() else "Off"}')
18+
19+
20+
for id, name in buttons.items():
21+
button: Gtk.Button = workbench.builder.get_object(id)
22+
button.connect("notify::active", on_active(name))

0 commit comments

Comments
 (0)