Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menubars aligning wrongly in wxPython

I am new to wxPython.I made a small program which tries to display menu bars on a small window. But when i click on menubars it randomly misbehaves by aliging at someother places.I am pasting my code here.My operating system is ubuntu 18.04. I have a top 3 menus and they have submenus .On clicking the menus seem to be aligned wrongly randomly as shown in picture.

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()
        newfile = 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.Append(wx.ID_ANY, 'I&mport', imp)

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

        self.Bind(wx.EVT_MENU, self.OnQuit, qmi)
        self.Bind(wx.EVT_MENU, self.onclick_subfile, newfile)
        menubar.Append(fileMenu, '&File')
        # Edit Menu
        editm = wx.Menu()
        editm.Append(wx.ID_UNDO, "Undo\tCtrl+Z")
        editm.Append(wx.ID_REDO, "Redo\tCtrl+Shift+Z")
        editm.Append(wx.ID_COPY, "Copy\tCtrl+C")
        editm.Append(wx.ID_CUT, "Cut\tCtrl+X")
        editm.Append(wx.ID_PASTE, "Paste\tCtrl+V")
        editm.Append(wx.ID_SELECTALL, "SelectAll\tCtrl+A")
        editm.AppendSeparator()

        menubar.Append(editm, "&Edit")

        services = wx.Menu()
        services.Append(wx.ID_UNDO, "Undo\tCtrl+Z")
        menubar.Append(services, "&Service")

        self.SetMenuBar(menubar)

        self.SetTitle('Billing System')
        self.Maximize(True)
        self.Centre()

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

        # **********HERE*************

    def onclick_subfile(self, event):
        frame = wx.Frame(None, -1, "My Second Frame")
        frame.Center()
        frame.Show()


def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()

enter image description here

like image 538
Midhun Raj Avatar asked Jul 27 '26 12:07

Midhun Raj


1 Answers

The problem seems to appear on the ubuntu. I tried that code on windows 10 and it is running and everything is aligned properly. I suggest using another python GUI library named tkinter.I had 0 issues with it on ubuntu.

like image 144
Aleksander Ikleiw Avatar answered Jul 30 '26 02:07

Aleksander Ikleiw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!