Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:49:54+00:00 2026-05-26T22:49:54+00:00

I imagine this is a noob question, though coming from a noob … it’s

  • 0

I imagine this is a noob question, though coming from a noob … it’s warranted. I have an app where a menu item exists that I want to use to call an external module (a wx.dialog). I imported the module as such:

from module_name import class_name

Now, I’m stumped on how to start the module when I press the menu item in my wxPython app?

Error:

Traceback (most recent call last):
File "C:\SQA_log\wxGui_comPort.py", line 141, in OnConvert
dlg = Converter(*args)
NameError: global name 'args' is not defined

Abridged code … for sake of brevity:
Menu bar from class:

    self.SetMenuBar(menuBar)
    self.Bind(wx.EVT_MENU, self.OnAbout, id=1)
    self.Bind(wx.EVT_MENU, self.OnQuit, id=2)
    self.Bind(wx.EVT_MENU, self.OnDisp, id=3)
    self.Bind(wx.EVT_MENU, self.OnServ, id=4)
    self.Bind(wx.EVT_MENU, self.OnDateTime, id=5)
    self.Bind(wx.EVT_MENU, self.OnOpen, id=6)
    self.Bind(wx.EVT_MENU, self.OnConvert, id=7)# Here is the menu item I'm using

The function called:

def OnConvert(self,e):
    dlg = Converter()
    dlg.ShowModal()
    dlg.Destroy()

This is the autonomous module/class:

import wx

class Converter(wx.Dialog):
    def __init__(self, parent, title):
        wx.Dialog.__init__(self, parent, title=title, size=(350, 310))

        wx.StaticText(self, -1, 'Convert Decimal to Hex', (20,20))
        wx.StaticText(self, -1, 'Decimal: ', (20, 80))
        wx.StaticText(self, -1, 'Hex: ', (20, 150))
        self.dec_hex =  wx.StaticText(self, -1, '', (150, 150))
        self.sc = wx.SpinCtrl(self, -1, '',  (150, 75), (60, -1))
        self.sc.SetRange(-459, 1000)
        self.sc.SetValue(0)
        compute_btn = wx.Button(self, 1, 'Compute', (70, 250))
        compute_btn.SetFocus()
        clear_btn = wx.Button(self, 2, 'Close', (185, 250))

        wx.EVT_BUTTON(self, 1, self.OnCompute)
        wx.EVT_BUTTON(self, 2, self.OnQuit)
        wx.EVT_CLOSE(self,  self.OnClose)

        self.Centre()
        self.ShowModal()
        self.Destroy()


    def OnCompute(self, event):
        dec = self.sc.GetValue()
        hex1 = "%x" % dec
        self.dec_hex.SetLabel(str(hex1).upper())

    def OnClose(self, event):
        self.Destroy()

    def OnQuit(self, event):
        self.Close(True)    

if __name__ == '__main__':
    app = wx.App(False)
    dlog = Converter(None, 'Converter')
    app.MainLoop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:49:54+00:00Added an answer on May 26, 2026 at 10:49 pm

    Bind the menu event to a menu handler and then in the event handler, you instantiate your class. So something like this:

    def myEventHandler(self, event):
       dlg = class_name(*args)
       dlg.ShowModal()
       dlg.Destroy()
    

    See also http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/ or http://wiki.wxpython.org/WorkingWithMenus

    EDIT: As is obvious, the Converter class accepts 3 arguments: self, parent and title. You have to provide those when you instantiate a dialog:

    dlg = Converter(None, "MyTitle")
    

    Here are some documentation links on dialogs and how to read tracebacks:

    • http://www.wxpython.org/docs/api/wx.Dialog-class.html
    • http://www.doughellmann.com/PyMOTW/traceback/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is really a noob quick question. Imagine you have a struct called No
Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding
Imagine this case where I have an object that I need to check a
Imagine this scenario: You have a desktop and a laptop. The desktop has a
Imagine this as the code from build.xml: <project name=test project> <target name=first> <echo>first</echo> </target>
So imagine this scenario, I have a list and it has a bit of
Imagine this: you have a Master-Child window consisting of a list of items (the
I imagine this must have a simple answer, but I am struggling: I want
So imagine this scenario: 10.00: your app pushes a message Hello 10.01: your app
Imagine this... I have a field in the database titled 'current_round'. This may only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.