Duck Man
Duck Man

Reputation: 11

hello world in wxPython gets no reaction at all, no frame, no return

First foray into python GUI and I'm using thenewboston tutorial. First lesson with a basic frame, I get an error that wx.PySimpleApp() is depreciated and I follow the instructions here to change it to wx.App(False). No errors come up, but also no frame. Here is the code:

#!/usr/bin/env python

import wx

class duckie(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id, 'Frame aka window', size = (300, 200))

if __name__=='__main__':
    app=wx.App(False)
    frame=duckie(parent=None,id=-1)
    frame.Show()
    app.MainLoop

Originally I had everything spaced out (space after commas, before and after operators, etc) but I changed it to more accurately follow the tutorial with no difference in effect. Understandably, I'm a little upset that I can't even get the Hello World to work here.

In case it's needed, the system is Ubuntu, everything is up to date through pip.


Solved.
For anyone else with this problem, I changed the id tag on line 10 from

frame=duckie(parent=None, id=-1)

to

frame=duckie(None, wx.ID_ANY)

Upvotes: 0

Views: 89

Answers (3)

Werner
Werner

Reputation: 2096

app.MainLoop

should be:

app.MainLoop()

'-1' or wx.ID_ANY is the same, do the following on a Python prompt:

import wx
wx.ID_ANY

The little sample I would probably do like this:

#!/usr/bin/env python

import wx


class Duckie(wx.Frame):

    def __init__(self, parent, *args, **kwargs):
        super(Duckie, self).__init__(parent, id=wx.ID_ANY,
                                     title='Frame aka window',
                                     size=(300, 200))

if __name__ == '__main__':
    app = wx.App(False)
    frame = Duckie(None)
    frame.Show()
    app.MainLoop()

The above code will pass PEP 8 (https://www.python.org/dev/peps/pep-0008/) checking and will also have no errors when one uses e.g. PyLint to check ones code.

Upvotes: 1

Duck Man
Duck Man

Reputation: 11

For anyone else with this problem, I changed the id tag on line 10 from

frame=duckie(parent=None, id=-1)

to

frame=duckie(None, wx.ID_ANY)

Upvotes: 0

Aswin Murugesh
Aswin Murugesh

Reputation: 11080

Is it a Typo in the last line? It has to be

app.MainLoop()

Upvotes: 0

Related Questions