简体   繁体   English

Python:下拉菜单

[英]Python:Drop down menu

I have create in wxPython this drop-down menu: 我在wxPython中创建了这个下拉菜单:

import wx


class Example(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 

        self.InitUI()

    def InitUI(self):

        menubar = wx.MenuBar()

        fileMenu = wx.Menu()
        fileMenu.Append(wx.ID_NEW, '&New')
        fileMenu.Append(wx.ID_OPEN, '&Open')
        fileMenu.Append(wx.ID_SAVE, '&Save')
        fileMenu.AppendSeparator()

        imp = wx.Menu()
        imp.Append(wx.ID_ANY, 'Import newsfeed list...')
        imp.Append(wx.ID_ANY, 'Import bookmarks...')
        imp.Append(wx.ID_ANY, 'Import mail...')

        fileMenu.AppendMenu(wx.ID_ANY, 'I&mport', imp)

        qmi = wx.MenuItem(fileMenu, wx.ID_EXIT, '&Quit\tCtrl+W')
        fileMenu.AppendItem(qmi)

        self.Bind(wx.EVT_MENU, self.OnQuit, qmi)

        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)

        self.SetSize((350, 250))
        self.SetTitle('Submenu')
        self.Centre()
        self.Show(True)

    def OnQuit(self, e):
        self.Close()

def main():

    ex = wx.App()
    Example(None)
    ex.MainLoop()    


if __name__ == '__main__':
    main()

My problem is when the mouse point to File automaticaly open all menu and see New,Open,Exit.see this example here to understand what exactly I want to make. 我的问题是当鼠标指向文件自动打开所有菜单并看到新建,打开,退出时。请参阅此示例以了解我想要做什么。

I belive it is outside the "spirit" of a cross-platform UI library to change the operating systems UI behaviour. 我相信它超出了跨平台UI库的“精神”,以改变操作系统的UI行为。

In most operating systems, menus won't automatically pop up on mouse over, so wxWindows doesn't do that either. 在大多数操作系统中,鼠标悬停时菜单不会自动弹出,因此wxWindows也不会这样做。

There might be a way to assing a mouseover listener to the menu, and have it automatically pop up, but I'd recommend against it, as this is not the usual behaviour (except for many web sites). 可能有一种方法可以让鼠标悬停监听器进入菜单,并自动弹出,但我建议不要这样做,因为这不是通常的行为(许多网站除外)。 It might also be that this is not possible, as it won't reliably work on all operating systems supported by wxWindows. 这也可能是,这是不可能的,因为它不会可靠地对wxWindows的支持所有操作系统。

I can't give you any details, as I've actually never used wxWindows. 我不能给你任何细节,因为我实际上从未使用过wxWindows。 I work on Linux only, and direct GTK is much more sensible then. 我只在Linux上工作,然后直接GTK更明智。

You may be able to use FlatMenu, a custom widget written in pure Python to do what you want. 您可以使用FlatMenu,一个用纯Python编写的自定义小部件来执行您想要的操作。 You can certainly hack it yourself a whole lot easier than the wxWidgets version. 你自己可以比wxWidgets版本更容易破解它。 Just so we're clear, wxPython wraps the native widgets as much as possible, so if that's normal behavior on the OS, then that's what wxPython will do too. 我们很清楚,wxPython尽可能地包装本机小部件,所以如果这是操作系统上的正常行为,那么wxPython也会这样做。 Which is why I think you should try FlatMenu. 这就是为什么我认为你应该尝试FlatMenu。 See here for documentation and an example: http://xoomer.virgilio.it/infinity77/AGW_Docs/flatmenu_module.html#flatmenu 请参阅此处获取文档和示例: http//xoomer.virgilio.it/infinity77/AGW_Docs/flatmenu_module.html#flatmenu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM