SEO Forums: Your seo discussion forum  
Welcome, Unregistered.
You last visited: Today at 04:22 AM
  #1 (permalink)  
Old 07-13-2008, 04:46 PM
teh_sAbEr
Guest
 
Posts: n/a
Default wxPython code giving strange errors.

I'm busy trying to learn wxPython, and i'm trying to run the following
piece of code (its from the wxPyWiki tutorial):

import wx

ID_ABOUT = 101
ID_EXIT = 110

class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =(200,100))
self.control = wx.TextCtrl(self,1,style=wx.TE_MULTILINE)
self.CreateStatusBar()

filemenu = wx.Menu()
filemenu.Append(ID_ABOUT,"&About"," Information about this
program.")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program.")

menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
self.Show(True)

app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

Simple enough, but every single time I try to run it IDLE gives me
this instead of the app I was hoping for:

Traceback (most recent call last):
File "C:\Documents and Settings\Enrico Jr\My Documents\Jr's Crap
\Python Stuff\Batch Picture Converter\main.py", line 24, in <module>
frame = MainWindow(None, -1, "Sample editor")
File "C:\Documents and Settings\Enrico Jr\My Documents\Jr's Crap
\Python Stuff\Batch Picture Converter\main.py", line 9, in __init__
wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =(200,100))
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx
\_windows.py", line 501, in __init__
_windows_.Frame_swiginit(self,_windows_.new_Frame( *args,
**kwargs))
PyNoAppError: The wx.App object must be created first!

As far as I can tell, the wx.App object IS being created first. I
suspect a race condition of some sort here, but can anyone shed some
light on this?
Reply With Quote
  #2 (permalink)  
Old 07-13-2008, 04:46 PM
Thin Myrna
Guest
 
Posts: n/a
Default Re: wxPython code giving strange errors.

teh_sAbEr wrote:

> I'm busy trying to learn wxPython, and i'm trying to run the following
> piece of code (its from the wxPyWiki tutorial):
>
> import wx
>
> ID_ABOUT = 101
> ID_EXIT = 110
>
> class MainWindow(wx.Frame):
> def __init__(self,parent,id,title):
> wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =(200,100))
> self.control = wx.TextCtrl(self,1,style=wx.TE_MULTILINE)
> self.CreateStatusBar()
>
> filemenu = wx.Menu()
> filemenu.Append(ID_ABOUT,"&About"," Information about this
> program.")
> filemenu.AppendSeparator()
> filemenu.Append(ID_EXIT,"E&xit"," Terminate the program.")
>
> menuBar = wx.MenuBar()
> menuBar.Append(filemenu,"&File")
> self.SetMenuBar(menuBar)
> self.Show(True)
>
> app = wx.PySimpleApp()
> frame = MainWindow(None, -1, "Sample editor")
> app.MainLoop()
>
> Simple enough, but every single time I try to run it IDLE gives me
> this instead of the app I was hoping for:
>
> Traceback (most recent call last):
> File "C:\Documents and Settings\Enrico Jr\My Documents\Jr's Crap
> \Python Stuff\Batch Picture Converter\main.py", line 24, in <module>
> frame = MainWindow(None, -1, "Sample editor")
> File "C:\Documents and Settings\Enrico Jr\My Documents\Jr's Crap
> \Python Stuff\Batch Picture Converter\main.py", line 9, in __init__
> wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =(200,100))
> File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx
> \_windows.py", line 501, in __init__
> _windows_.Frame_swiginit(self,_windows_.new_Frame( *args,
> **kwargs))
> PyNoAppError: The wx.App object must be created first!
>
> As far as I can tell, the wx.App object IS being created first. I
> suspect a race condition of some sort here, but can anyone shed some
> light on this?


The main frame has to be created by the app itself, e.g. like so:


class App(wx.App):

def OnInit(self):

self._frame = MainFrame( None, -1, _APP_CAPTION)
self._frame.Show( True)
self.SetTopWindow( self._frame)
return True


def Run():
app = App()
app.MainLoop()


if __name__ == '__main__':
Run()


HTH
Thin

Reply With Quote
  #3 (permalink)  
Old 07-13-2008, 11:54 PM
Mike Driscoll
Guest
 
Posts: n/a
Default Re: wxPython code giving strange errors.

On Jul 13, 10:18*am, teh_sAbEr <teh.sa...@gmail.com> wrote:
> I'm busy trying to learn wxPython, and i'm trying to run the following
> piece of code (its from the wxPyWiki tutorial):
>
> import wx
>
> ID_ABOUT = 101
> ID_EXIT = 110
>
> class MainWindow(wx.Frame):
> * * def __init__(self,parent,id,title):
> * * * * wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =(200,100))
> * * * * self.control = wx.TextCtrl(self,1,style=wx.TE_MULTILINE)
> * * * * self.CreateStatusBar()
>
> * * * * filemenu = wx.Menu()
> * * * * filemenu.Append(ID_ABOUT,"&About"," Information about this
> program.")
> * * * * filemenu.AppendSeparator()
> * * * * filemenu.Append(ID_EXIT,"E&xit"," Terminate the program.")
>
> * * * * menuBar = wx.MenuBar()
> * * * * menuBar.Append(filemenu,"&File")
> * * * * self.SetMenuBar(menuBar)
> * * * * self.Show(True)
>
> app = wx.PySimpleApp()
> frame = MainWindow(None, -1, "Sample editor")
> app.MainLoop()
>
> Simple enough, but every single time I try to run it IDLE gives me
> this instead of the app I was hoping for:
>
> Traceback (most recent call last):
> * File "C:\Documents and Settings\Enrico Jr\My Documents\Jr's Crap
> \Python Stuff\Batch Picture Converter\main.py", line 24, in <module>
> * * frame = MainWindow(None, -1, "Sample editor")
> * File "C:\Documents and Settings\Enrico Jr\My Documents\Jr's Crap
> \Python Stuff\Batch Picture Converter\main.py", line 9, in __init__
> * * wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =(200,100))
> * File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx
> \_windows.py", line 501, in __init__
> * * _windows_.Frame_swiginit(self,_windows_.new_Frame( *args,
> **kwargs))
> PyNoAppError: The wx.App object must be created first!
>
> As far as I can tell, the wx.App object IS being created first. I
> suspect a race condition of some sort here, but can anyone shed some
> light on this?


This code works "as is" on Windows XP. However, I have gotten this
error when trying to run it from IDLE and I've heard that that can
happen in other Tkinter-based IDEs. Try running it from the command
line and I'll bet you won't get that error.

Also, there's a great wxPython user's group you can join from the
official website:

www.wxpython.org

Mike
Reply With Quote
  #4 (permalink)  
Old 07-18-2008, 09:37 PM
David C. Ullrich
Guest
 
Posts: n/a
Default Re: wxPython code giving strange errors.

In article
<c21e91f7-2feb-4dbc-96ab-05110e3b2127@34g2000hsh.googlegroups.com>,
Mike Driscoll <kyosohma@gmail.com> wrote:

> On Jul 13, 10:18*am, teh_sAbEr <teh.sa...@gmail.com> wrote:
> > I'm busy trying to learn wxPython, and i'm trying to run the following
> > piece of code (its from the wxPyWiki tutorial):
> >
> > import wx
> >

[...]
> >
> > app = wx.PySimpleApp()
> > frame = MainWindow(None, -1, "Sample editor")
> > app.MainLoop()
> >[...]

>
> This code works "as is" on Windows XP. However, I have gotten this
> error when trying to run it from IDLE and I've heard that that can
> happen in other Tkinter-based IDEs.


So I've heard. Just for fun I tried running it in a wxPython-based
shell - it worked fine.

> Try running it from the command
> line and I'll bet you won't get that error.
>
> Also, there's a great wxPython user's group you can join from the
> official website:
>
> www.wxpython.org
>
> Mike


--
David C. Ullrich
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:22 AM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Reklamlar & Desteklenenler