我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用gtk.MenuBar()。
def build_Menu(self): menu1 = gtk.Menu(); menu2 = gtk.Menu(); menuItem1_1 = gtk.MenuItem("1:1"); menuItem1_2 = gtk.MenuItem("1:2"); menuItem1_3 = gtk.MenuItem("1:3"); menuItem2_1 = gtk.MenuItem("??"); menuItem2_2 = gtk.MenuItem("??"); menuItem2_3 = gtk.MenuItem("????"); menuItem2_4 = gtk.MenuItem("?????"); menuItem2_5 = gtk.MenuItem("????"); menuItem2_6 = gtk.MenuItem("?????"); menuItem2_7 = gtk.MenuItem("????") menu1.append(menuItem1_1) menu1.append(menuItem1_2) menu1.append(menuItem1_3) menu2.append(menuItem2_1) menu2.append(menuItem2_2) menu2.append(menuItem2_3) menu2.append(menuItem2_4) menu2.append(menuItem2_5) menu2.append(menuItem2_6) menu2.append(menuItem2_7) first_menu = gtk.MenuItem("First Menu") second_menu = gtk.MenuItem("?????") first_menu.set_submenu(menu1) second_menu.set_submenu(menu2) menuItem2_1.connect("button-press-event",self.select_Server,1); menuItem2_2.connect("button-press-event",self.select_Server,2); menuItem2_3.connect("button-press-event",self.select_Server,3); menuItem2_4.connect("button-press-event",self.add_Server); menuItem2_5.connect("button-press-event",self.create_Excel); menuItem2_7.connect("button-press-event",self.load_information); menu_bar = gtk.MenuBar() menu_bar.append (first_menu) menu_bar.append (second_menu) return menu_bar
def _main_window_indicator(self, menu_container, icon_container): if not self._HAVE_INDICATOR: menubar = gtk.MenuBar() im = gtk.MenuItem(self.config.get('app_name', 'GUI-o-Matic')) im.set_submenu(self.menu) menubar.append(im) menu_container.pack_start(menubar, False, True) icon = gtk.Image() icon_container.pack_start(icon, False, True) self.main_window['indicator_icon'] = icon