TLSK
TLSK

Reputation: 273

Python:Drop down menu

I have create in wxPython this drop-down menu:

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.

Upvotes: 0

Views: 2076

Answers (2)

Mike Driscoll
Mike Driscoll

Reputation: 33111

You may be able to use FlatMenu, a custom widget written in pure Python to do what you want. You can certainly hack it yourself a whole lot easier than the wxWidgets version. 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. Which is why I think you should try FlatMenu. See here for documentation and an example: http://xoomer.virgilio.it/infinity77/AGW_Docs/flatmenu_module.html#flatmenu

Upvotes: 1

Has QUIT--Anony-Mousse
Has QUIT--Anony-Mousse

Reputation: 77495

I belive it is outside the "spirit" of a cross-platform UI library to change the operating systems UI behaviour.

In most operating systems, menus won't automatically pop up on mouse over, so wxWindows doesn't do that either.

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.

I can't give you any details, as I've actually never used wxWindows. I work on Linux only, and direct GTK is much more sensible then.

Upvotes: 1

Related Questions