Unable to run basic WxPython GUI script from tutorial. Inconsistences in Windows 7, bad install?

Install the docs and demos and see if these run.

Use pastebin for the sample code so we can check indentation.

Cheers,

T

···

Am 22.01.2013 um 23:02 schrieb Michael Webb wonkishere@gmail.com:

General Information:

I hear a lot of great things about wxpython, and I want to
get familiar with using the GUI, so I’ve made several stabs at getting it to
work. I’ve been trying to get wxpython
to work consistently on my machine for many months, having abandoned it and
walked away several times and then come back to experience more frustration.

I have the very strong feeling that there is something wrong
with my installation, but I don’t understand what it is. I have installed and re-installed the package
and nothing helps. I install python
scripts by directly copying the entire script from a web page and running it…
and it doesn’t do the same thing on my machine it does on other machines. Frequently it creates a window with no
widgets, and can only be closed through the task manager, as in this case. It’s driving me insane.

I used to like python but i’m wondering if I’d should walk
away from the language at this point, maybe try to learn programming with a
different language because the inconsistences are making it impossible for me
to progress now. I don’t know how to
learn a language that seems to perform differently for everyone else.

I run Windows 7, Python 2.7.3, and use the Idle GUI. If anybody has experienced similar problems
please let me know.

Specific Script:

I copied this script from a tutorial. Evidently it works for most people, but in my
case it opens a window labeled wxHello with the inside greyed out and no
widgets.

import wx

class wxHelloFrame(wx.Frame):

“”"This
is the frame for our application, it is derived from

the
wx.Frame element.“”"

def
init(self, *args, **kwargs):

“”“Initialize,
and let the user set any Frame settings”“”

wx.Frame.init(self,
*args, **kwargs)

self.create_controls()

def
create_controls(self):

“”“Called
when the controls on Window are to be created”“”

pass

class wxHelloApp(wx.App):

“”“The
wx.App for the wxHello application”“”

def
OnInit(self):

“”“Override
OnInit to create our Frame”“”

frame
= wxHelloFrame(None, title=“wxHello”)

frame.Show()

self.SetTopWindow(frame)

return
True

def create_controls(self):

“”“Called
when the controls on Window are to be created”“”

Horizontal sizer

self.h_sizer
= wx.BoxSizer(wx.HORIZONTAL)

Create

the static text widget and set the text

self.text =
wx.StaticText(self, label=“Enter some text:”)

#Create the
Edit Field (or TextCtrl)

self.edit =
wx.TextCtrl(self, size=wx.Size(250, -1))

#Add to
horizontal sizer

#add the
static text to the sizer, tell it not to resize

self.h_sizer.Add(self.text,
0,)

#Add 5
pixels between the static text and the edit

self.h_sizer.AddSpacer((5,0))

#Add Edit

self.h_sizer.Add(self.edit,
1)

#Set the
sizer

self.SetSizer(self.h_sizer)

if name == “main”:

app =
wxHelloApp()

app.MainLoop()

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Nothing worse than frustration. But hang on in there.

I’ve taken a quick look at the code and I do not (at this point) see how create_controls gets called. You have defined a class with a method called create_controls, but this just executes the Python pass instruction. Further on in the code you define a function called create_controls that is, as far as I can make out, never called.

I’ll copy the code, check this out and get back to you.

Cheers!!

Dermot.

···

On 23 January 2013 08:15, Tobias Weber tobias.weber@roglink.net wrote:

Am 22.01.2013 um 23:02 schrieb Michael Webb wonkishere@gmail.com:

General Information:

I hear a lot of great things about wxpython, and I want to
get familiar with using the GUI, so I’ve made several stabs at getting it to
work. I’ve been trying to get wxpython
to work consistently on my machine for many months, having abandoned it and
walked away several times and then come back to experience more frustration.

I have the very strong feeling that there is something wrong
with my installation, but I don’t understand what it is. I have installed and re-installed the package
and nothing helps. I install python
scripts by directly copying the entire script from a web page and running it…
and it doesn’t do the same thing on my machine it does on other machines. Frequently it creates a window with no
widgets, and can only be closed through the task manager, as in this case. It’s driving me insane.

I used to like python but i’m wondering if I’d should walk
away from the language at this point, maybe try to learn programming with a
different language because the inconsistences are making it impossible for me
to progress now. I don’t know how to
learn a language that seems to perform differently for everyone else.

I run Windows 7, Python 2.7.3, and use the Idle GUI. If anybody has experienced similar problems
please let me know.

Specific Script:

I copied this script from a tutorial. Evidently it works for most people, but in my
case it opens a window labeled wxHello with the inside greyed out and no
widgets.

import wx

class wxHelloFrame(wx.Frame):

“”"This
is the frame for our application, it is derived from

the
wx.Frame element.“”"

def
init(self, *args, **kwargs):

“”“Initialize,
and let the user set any Frame settings”“”

wx.Frame.init(self,
*args, **kwargs)

self.create_controls()

def
create_controls(self):

“”“Called
when the controls on Window are to be created”“”

pass

class wxHelloApp(wx.App):

“”“The
wx.App for the wxHello application”“”

def
OnInit(self):

“”“Override
OnInit to create our Frame”“”

frame
= wxHelloFrame(None, title=“wxHello”)

frame.Show()

self.SetTopWindow(frame)

return
True

def create_controls(self):

“”“Called
when the controls on Window are to be created”“”

Horizontal sizer

self.h_sizer
= wx.BoxSizer(wx.HORIZONTAL)

Create

the static text widget and set the text

self.text =
wx.StaticText(self, label=“Enter some text:”)

#Create the
Edit Field (or TextCtrl)

self.edit =
wx.TextCtrl(self, size=wx.Size(250, -1))

#Add to
horizontal sizer

#add the
static text to the sizer, tell it not to resize

self.h_sizer.Add(self.text,
0,)

#Add 5
pixels between the static text and the edit

self.h_sizer.AddSpacer((5,0))

#Add Edit

self.h_sizer.Add(self.edit,
1)

#Set the
sizer

self.SetSizer(self.h_sizer)

if name == “main”:

app =
wxHelloApp()

app.MainLoop()

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Install the docs and demos and see if these run.

Use pastebin for the sample code so we can check indentation.

Cheers,

T

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Hello Michael,

That took less time than I thought it would. The problem with your program appears to be as I stated in my previous reply. I’ve attached a new version of the program that simply moves the function “create_controls” under the definition of class “wxHelloFrame”. Placing that code here makes it a method of the class. What you will now see are two definitions for the method “create_controls”, but the second redefines the first. You can just remove the first definition as it is not needed.

The resulting program is not pretty, but at least you are now a step further and, I hope, just a little bit less frustrated. I recommend getting used to using Python classes first before you dig further into wxPython. It will actually be a small investment of time and will help save your sanity. The online tutorial for Python (http://docs.python.org/2/tutorial/classes.html) should be enough.

Cheers!!

Dermot

P.S.

Please don’t give, but forge on. Every language has a learning curve. I speak from experience having had to learn Dutch :slight_smile:

problem_python.py (2.25 KB)

···

On 23 January 2013 10:17, Dermot Doran dppdoran@gmail.com wrote:

Nothing worse than frustration. But hang on in there.

I’ve taken a quick look at the code and I do not (at this point) see how create_controls gets called. You have defined a class with a method called create_controls, but this just executes the Python pass instruction. Further on in the code you define a function called create_controls that is, as far as I can make out, never called.

I’ll copy the code, check this out and get back to you.

Cheers!!

Dermot.

On 23 January 2013 08:15, Tobias Weber tobias.weber@roglink.net wrote:

Am 22.01.2013 um 23:02 schrieb Michael Webb wonkishere@gmail.com:

General Information:

I hear a lot of great things about wxpython, and I want to
get familiar with using the GUI, so I’ve made several stabs at getting it to
work. I’ve been trying to get wxpython
to work consistently on my machine for many months, having abandoned it and
walked away several times and then come back to experience more frustration.

I have the very strong feeling that there is something wrong
with my installation, but I don’t understand what it is. I have installed and re-installed the package
and nothing helps. I install python
scripts by directly copying the entire script from a web page and running it…
and it doesn’t do the same thing on my machine it does on other machines. Frequently it creates a window with no
widgets, and can only be closed through the task manager, as in this case. It’s driving me insane.

I used to like python but i’m wondering if I’d should walk
away from the language at this point, maybe try to learn programming with a
different language because the inconsistences are making it impossible for me
to progress now. I don’t know how to
learn a language that seems to perform differently for everyone else.

I run Windows 7, Python 2.7.3, and use the Idle GUI. If anybody has experienced similar problems
please let me know.

Specific Script:

I copied this script from a tutorial. Evidently it works for most people, but in my
case it opens a window labeled wxHello with the inside greyed out and no
widgets.

import wx

class wxHelloFrame(wx.Frame):

“”"This
is the frame for our application, it is derived from

the
wx.Frame element.“”"

def
init(self, *args, **kwargs):

“”“Initialize,
and let the user set any Frame settings”“”

wx.Frame.init(self,
*args, **kwargs)

self.create_controls()

def
create_controls(self):

“”“Called
when the controls on Window are to be created”“”

pass

class wxHelloApp(wx.App):

“”“The
wx.App for the wxHello application”“”

def
OnInit(self):

“”“Override
OnInit to create our Frame”“”

frame
= wxHelloFrame(None, title=“wxHello”)

frame.Show()

self.SetTopWindow(frame)

return
True

def create_controls(self):

“”“Called
when the controls on Window are to be created”“”

Horizontal sizer

self.h_sizer
= wx.BoxSizer(wx.HORIZONTAL)

Create

the static text widget and set the text

self.text =
wx.StaticText(self, label=“Enter some text:”)

#Create the
Edit Field (or TextCtrl)

self.edit =
wx.TextCtrl(self, size=wx.Size(250, -1))

#Add to
horizontal sizer

#add the
static text to the sizer, tell it not to resize

self.h_sizer.Add(self.text,
0,)

#Add 5
pixels between the static text and the edit

self.h_sizer.AddSpacer((5,0))

#Add Edit

self.h_sizer.Add(self.edit,
1)

#Set the
sizer

self.SetSizer(self.h_sizer)

if name == “main”:

app =
wxHelloApp()

app.MainLoop()

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Install the docs and demos and see if these run.

Use pastebin for the sample code so we can check indentation.

Cheers,

T

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en