Search code examples
pythonpython-3.xwxpython

WxPython: 'App' object has no attribute 'Mainloop'


So, I was trying to do the RealPython tutorial on making apps with WxPython, and I ran into an error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'App' object has no attribute 'Mainloop'

I have tried everything, but it always gives me that error.

How do I fix it?

For reference, here is the code I was trying to run:

import wx
app = wx.App()
frame = wx.Frame(parent=None, title="Hello, world!")
frame.Show()
app.Mainloop()

Solution

  • app has a MainLoop attribute, not a Mainloop note the Capital "L"

    For future reference you can use the dir function i.e.

    print (dir(app))
    

    that will show you what is available.

    import wx
    app = wx.App()
    frame = wx.Frame(parent=None, title="Hello, world!")
    frame.Show()
    app.MainLoop()
    

    enter image description here