1 | |
---|
2 | from gi.repository import Gtk |
---|
3 | |
---|
4 | class MenuTest(Gtk.Window): |
---|
5 | |
---|
6 | def __init__(self): |
---|
7 | super(MenuTest, self).__init__() |
---|
8 | |
---|
9 | self.set_title("Click the menu to update the counter!") |
---|
10 | |
---|
11 | mb = Gtk.MenuBar() |
---|
12 | menu_item = Gtk.MenuItem("Add 1") |
---|
13 | menu_item.connect("activate", self.on_menu_item_activate) |
---|
14 | mb.append(menu_item) |
---|
15 | |
---|
16 | vbox = Gtk.VBox() |
---|
17 | vbox.pack_start(mb, False, False, 0) |
---|
18 | self.add(vbox) |
---|
19 | self.label = Gtk.Label('Test!') |
---|
20 | vbox.pack_start(self.label, False, False, 0) |
---|
21 | |
---|
22 | self.connect("destroy", Gtk.main_quit) |
---|
23 | self.show_all() |
---|
24 | self._counter = 0 |
---|
25 | |
---|
26 | def on_menu_item_activate(self, widget): |
---|
27 | self._counter += 1 |
---|
28 | self.label.set_text(str(self._counter)) |
---|
29 | |
---|
30 | |
---|
31 | MenuTest() |
---|
32 | Gtk.main() |
---|