-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathspinbutton_example.py
More file actions
46 lines (34 loc) · 1.45 KB
/
spinbutton_example.py
File metadata and controls
46 lines (34 loc) · 1.45 KB
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
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class SpinButtonWindow(Gtk.Window):
def __init__(self):
super().__init__(title="SpinButton Demo")
self.set_border_width(10)
hbox = Gtk.Box(spacing=6)
self.add(hbox)
adjustment = Gtk.Adjustment(upper=100, step_increment=1, page_increment=10)
self.spinbutton = Gtk.SpinButton()
self.spinbutton.set_adjustment(adjustment)
self.spinbutton.connect("value-changed", self.on_value_changed)
hbox.pack_start(self.spinbutton, False, False, 0)
check_numeric = Gtk.CheckButton(label="Numeric")
check_numeric.connect("toggled", self.on_numeric_toggled)
hbox.pack_start(check_numeric, False, False, 0)
check_ifvalid = Gtk.CheckButton(label="If Valid")
check_ifvalid.connect("toggled", self.on_ifvalid_toggled)
hbox.pack_start(check_ifvalid, False, False, 0)
def on_value_changed(self, scroll):
print(self.spinbutton.get_value_as_int())
def on_numeric_toggled(self, button):
self.spinbutton.set_numeric(button.get_active())
def on_ifvalid_toggled(self, button):
if button.get_active():
policy = Gtk.SpinButtonUpdatePolicy.IF_VALID
else:
policy = Gtk.SpinButtonUpdatePolicy.ALWAYS
self.spinbutton.set_update_policy(policy)
win = SpinButtonWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()