亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

pygtk-menu

系統 2112 0
    #!/usr/bin/env python

# example menu.py

import pygtk
pygtk.require('2.0')
import gtk

class MenuExample:
    def __init__(self):
         # create a new window
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.set_size_request(200, 100)
        window.set_title("GTK Menu Test")
        window.connect("delete_event", lambda w,e: gtk.main_quit())

        # Init the menu-widget, and remember -- never
        # show() the menu widget!!
        # This is the menu that holds the menu items, the one that
        # will pop up when you click on the "Root Menu" in the app
        menu = gtk.Menu()

        # Next we make a little loop that makes three menu-entries for
        # "test-menu". Notice the call to gtk_menu_append. Here we are
        # adding a list of menu items to our menu. Normally, we’d also
        # catch the "clicked" signal on each of the menu items and setup a
        # callback for it, but it’s omitted here to save space.
        for i in range(3):
            # Copy the names to the buf.
            buf = "Test-undermenu - %d" % i

            # Create a new menu-item with a name...
            menu_items = gtk.MenuItem(buf)

            # ...and add it to the menu.
            menu.append(menu_items)

            # Do something interesting when the menuitem is selected
            menu_items.connect("activate", self.menuitem_response, buf)

            # Show the widget
            menu_items.show()

        # This is the root menu, and will be the label
        # displayed on the menu bar. There won’t be a signal handler attached,
        # as it only pops up the rest of the menu when pressed.
        root_menu = gtk.MenuItem("Root Menu")

        root_menu.show()

        # Now we specify that we want our newly created "menu" to be the
        # show() the menu widget!!
        # This is the menu that holds the menu items, the one that
        # will pop up when you click on the "Root Menu" in the app
        menu = gtk.Menu()

        # Next we make a little loop that makes three menu-entries for
        # "test-menu". Notice the call to gtk_menu_append. Here we are
        # adding a list of menu items to our menu. Normally, we’d also
        # catch the "clicked" signal on each of the menu items and setup a
        # callback for it, but it’s omitted here to save space.
        for i in range(3):
            # Copy the names to the buf.
            buf = "Test-undermenu - %d" % i

            # Create a new menu-item with a name...
            menu_items = gtk.MenuItem(buf)

            # ...and add it to the menu.
            menu.append(menu_items)

            # Do something interesting when the menuitem is selected
            menu_items.connect("activate", self.menuitem_response, buf)

            # Show the widget
            menu_items.show()

            # This is the root menu, and will be the label
            # displayed on the menu bar. There won’t be a signal handler attached,
            # as it only pops up the rest of the menu when pressed.
        root_menu = gtk.MenuItem("Root Menu")
        root_menu.show()

# menu for the "root menu"
        root_menu.set_submenu(menu)
        
        # A vbox to put a menu and a button in:
        vbox = gtk.VBox(False, 0)
        window.add(vbox)
        vbox.show()
        
        # Create a menu-bar to hold the menus and add it to our main window
        menu_bar = gtk.MenuBar()
        vbox.pack_start(menu_bar, False, False, 2)
        menu_bar.show()
        
        # Create a button to which to attach menu as a popup
        button = gtk.Button("press me")
        button.connect_object("event", self.button_press, menu)
        vbox.pack_end(button, True, True, 2)
        button.show()
    
        # And finally we append the menu-item to the menu-bar -- this is th         
    
                # Now we specify that we want our newly created "menu" to be the
                # "root" menu-item I have been raving about =)
        menu_bar.append (root_menu)
    
            # always display the window as the last step so it all splashes on
            # the screen at once.
        window.show()

     # Respond to a button-press by posting a menu passed in as widget.
     #
     # Note that the "widget" argument is the menu being posted, NOT
     # the button that was pressed.
    def button_press(self, widget, event):
        if event.type == gtk.gdk.BUTTON_PRESS:
            widget.popup(None, None, None, event.button, event.time)
        # Tell calling code that we have handled this event the buck
        # stops here.
            return True
        # Tell calling code that we have not handled this event pass it on.
        return False

     # Print a string when a menu item is selected
    def menuitem_response(self, widget, string):
        print "%s" % string

def main():
    gtk.main()
    return 0

if __name__ == "__main__":
    MenuExample()
    main()

  

?file_menu = gtk.Menu()

將file_item做為子菜單加入到file_menu

file_item.set_submenu(file_menu)
在menubar中加入菜單項

menu_bar.append(child)

比如:
menu_bar.append(file_item)

在menubar中右調整,比如help菜單等,我們使用下面的方法:

menu_item.set_right_justified(right_justified)
=========================
1.使用gtk.Menu()創建新的menu

2.gtk.MenuItem() 創建子菜單項,然后使用append()

3. set_submenu() 將子菜單項加入menu中

4.使用gtk.MenuBar()創建menubar

5.append()加入菜單項

6.設置事件

widget.connect_object("event", handler, menu)

?
pygtk-menu
?
pygtk-menu
?

?

?

?

pygtk-menu


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 色婷婷香蕉| 国产一级αv片免费观看 | 爽爽影院免费观看视频 | 国产亚洲精aa在线观看不卡 | 久久精品国产精品亚洲艾 | 免费观看一级特黄三大片视频 | 欧美在线精品一区二区三区 | 久久99热久久精品91 | 伊人久热这里只有精品视频99 | 日本二三区 | 久久99国产亚洲高清观看韩国 | 精品国产亚一区二区三区 | 色综合久久中文字幕综合网 | 日韩中文字幕一区二区不卡 | 亚洲精品入口一区二区在线观看 | 国产精品久久久久久久午夜片 | 欧美在线观看一区 | 97影院网 | 日本爱爱免费视频 | 久久精品在现线观看免费15 | 女人18毛片a级毛片免费看一 | 久久99精品久久久久久园产越南 | 色费女人18毛片a级视频在线 | 夜夜夜夜夜夜爽噜噜噜噜噜噜 | 免费性视频| 中文字幕日韩女同互慰视频 | 午夜在线观看网站 | 婷婷在线观看视频 | 亚洲综合精品成人啪啪 | 五月天婷婷免费视频 | 色综合天天综合 | 国产伦理精品 | 欧美精品www | 奇米777777 | 国产欧美精品区一区二区三区 | 欧美成人免费mv在线播放 | 日日噜噜夜夜狠狠视频无 | 青青青青青国产免费观看 | 国产精品久久久久激情影院 | 看黄色一级毛片 | 免费看黄色的网站 |