3

I am trying to write a timetabling program using wxpython for gui and am using the getting started tutorial on the wxpython wiki to get up to speed with wxpython but when I try to add a menu bar to wxFrame, the menu bar does not show. Any ideas why this is happening? I am using ubuntu 10.10 and python 2.7. The code is given below:

#! /usr/bin/env python2.7
import wx, os

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(200,100))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.CreateStatusBar() # A Statusbar in the bottom of the window


        # Creating the menubar.
        menuBar = wx.MenuBar()

         # Setting up the menu.
        filemenu= wx.Menu()

        # wx.ID_ABOUT and wx.ID_EXIT are standard ids provided by wxWidgets.
        menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

        # Set events.
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)

        self.Show(True)


    def OnAbout(self,e):

        # A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
        dlg = wx.MessageDialog( self, "A small text editor", "About Sample Editor", wx.OK)
        dlg.ShowModal() # Show it
        dlg.Destroy() # finally destroy it when finished.

    def OnExit(self,e):
        self.Close(True)  # Close the frame.
        ''' 
        # wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets.
        filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        self.Show(True)
        '''

app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()
4
  • Without seeing the code, it's impossible to say. Feb 16, 2011 at 23:21
  • Works fine for me under Winxp, python 2.6 and wx 2.8.10 Feb 17, 2011 at 1:50
  • Works here as well. Does anything change if you disable desktop effects? I've had problems in the past with older cards or outdated drivers not handling transparency properly, causing some interface elements to disappear.
    – robots.jpg
    Feb 17, 2011 at 15:35
  • I have this same problem, but just for one window. All the others the MenuBar works fine... Mar 20, 2021 at 2:28

5 Answers 5

6

I had the same error and I solved it no using standard IDs provided by wxWidgets.

Try with this:

# wx.ID_ABOUT and wx.ID_EXIT are standard ids provided by wxWidgets.
menuAbout = filemenu.Append(102, "&About"," Information about this program")
menuExit = filemenu.Append(103,"E&xit"," Terminate the program")
1
  • This fixed it for me as well.
    – Technoloft
    Jan 14, 2019 at 23:19
4

Someone had a similar issue on the wxPython list. I think the menu was appearing in the "taskbar" or something because the OS had been configured for that, kind of like a Mac. If you're using a custom theme, try a standard one instead. You can also try running the wxPython demo to see if it has the same issue.

0
3

add this to ~/.bashrc:

export UBUNTU_MENUPROXY=0

from https://bugs.launchpad.net/ubuntu/+source/wxwidgets2.8/+bug/682478

1
  • This is the right answer! Don't forget to open a new terminal, so changes are taken into account
    – Jacques
    Feb 13, 2017 at 18:48
2

Somehow it is not a wxpython problem. It is a feature. It is supposed to behavior in this way.

Apple and Microsoft specify slightly different layouts for menubars. (Apple specification. Microsoft specification.) WxWidgets will automatically move certain menus on a Macintosh, to ease the task of writing cross-platform applications with native look and feel on both MS-Windows and Apple Macintosh;

The About/Exit menu item would locate at the dock menu.

enter image description here

Check: https://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X

1

I had the same problem where i could not see the menu bar because it as in the "taskbar" way up there. So you can just add this to your python script if you do not want to permanantly change your .bashrc file

import os
os.environ["UBUNTU_MENUPROXY"]="0"
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy