Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python – popup menu in wxPython

  • Last Updated : 15 May, 2020

In this article we are going to know how can we create a popupmenu in wxPython. We will write a code when we click right on screen a popup menu will show up with menu items names as ‘one’ and ‘two’.

Syntax :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

wx.Window.PopupMenu(self, menu, pos)

Parameters :

ParameterInput TypeDescription
menuwx.MenuMenu in popupmenu.
pointwx.Pointpoint of popup menu.

Code Example :

import wx
class PopMenu(wx.Menu):
    def __init__(self, parent):
        super(PopMenu, self).__init__()
        self.parent = parent
        # menu item 1
        popmenu = wx.MenuItem(self, wx.NewId(), 'one ')
        # menu item 2
        popmenu2 = wx.MenuItem(self, wx.NewId(), 'two')
class Example(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    def InitUI(self):
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        self.SetSize((600, 400))
        self.SetTitle('Popup Menu')
    def OnRightDown(self, e):
        # sow popu menu
        self.PopupMenu(PopMenu(self), e.GetPosition())
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :