将 GtkMenuBar 与其他小部件并置?

发布于 2024-12-11 08:13:08 字数 242 浏览 0 评论 0原文

是否可以将 GtkMenuBar 与其他小部件放在一起,而不是显示在该窗口的顶部?

或者我可以使用按钮,但是当您将鼠标悬停在这些按钮上时,按钮上的菜单不会仅仅表现得像一个菜单,也就是说,当您靠近一个菜单时item,菜单直接弹出,无需点击,其他menu自动隐藏。我可以制作这样的按钮吗?或者其他可能具有:标签、图像和弹出菜单项的小部件也很酷。

任何想法表示赞赏。

Is it possible to place a GtkMenuBar with other widgets together , instead of showing at the top of that window ?

Or i could use buttons , but when you hover your mouse over those buttons , the menu on the buttons won't just behave like a menu , which is , when you are close to one menu item , the menu pops down directly , without click , and other menu hide automatically. Can i make buttons like that ? Or other widgets that could have: label , image , and pop down menu item is cool.

Any ideas is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贵在坚持 2024-12-18 08:13:08

也许连接到按钮的“enter-notify-event”和“leave-notify-event”可以帮助您完成该操作,例如分别显示和隐藏弹出菜单。


编辑

我终于忘记了那些行为有点复杂的“进入”和“离开”事件,而只使用了“motion-notify-event”......

现在我希望这是你想要的!

#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk

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

        # A vbox to put a button in:
        vbox = gtk.VBox(False, 0)
        self.window.add(vbox)
        vbox.show()
        self.popped = False

        # Create a button to simulate a menu
        button = gtk.Button("press me")
        vbox.pack_start(button, False, False, 2)
        self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self.window.connect("motion-notify-event", self.wakeup)
        self.window.show_all()
        self.bmenu = gtk.Button("A single entry menu")
        self.bmenu.connect("clicked", self. menuitem_response, "Click on the magic menu !")
        vbox.pack_start(self.bmenu, False, False, 2)

    def wakeup(self, widget, event):
        #print "Event number %d woke me up" % event.type
        (x, y) = self.window.get_pointer() 
        if y < 30:
            if self.popped == False:
                self.popped = True
                self.bmenu.show()
        elif y > 60:
            if self.popped == True:
                self.popped = False
                self.bmenu.hide()

    # 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()

Maybe the "enter-notify-event" and "leave-notify-event", connected to buttons, may help you do the thing, with for example, a popup menu show and hide respectively.


EDIT

I finally forgot those "enter" and "leave" events whose behaviour was a little complex, and just used the "motion-notify-event"...

Now I hope it is what you want !

#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk

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

        # A vbox to put a button in:
        vbox = gtk.VBox(False, 0)
        self.window.add(vbox)
        vbox.show()
        self.popped = False

        # Create a button to simulate a menu
        button = gtk.Button("press me")
        vbox.pack_start(button, False, False, 2)
        self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self.window.connect("motion-notify-event", self.wakeup)
        self.window.show_all()
        self.bmenu = gtk.Button("A single entry menu")
        self.bmenu.connect("clicked", self. menuitem_response, "Click on the magic menu !")
        vbox.pack_start(self.bmenu, False, False, 2)

    def wakeup(self, widget, event):
        #print "Event number %d woke me up" % event.type
        (x, y) = self.window.get_pointer() 
        if y < 30:
            if self.popped == False:
                self.popped = True
                self.bmenu.show()
        elif y > 60:
            if self.popped == True:
                self.popped = False
                self.bmenu.hide()

    # 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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文