Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

trouble with wxPython intro


I'm trying to learn WxPython with the tutorial:
http://wiki.wxpython.org/Getting_Started

But I can't seem to get the example for events to work. I pasted the
code they had directly into an interpreter and it got a dialog to
appear and the program was able to close itself, but my own copy won't
work. As far as I can see, it isn't at all different except for the
name of the main frame, and so I differ to you for help.

my own code:
#!/usr/bin/python

import wx

ID_ABOUT=101
ID_EXIT=110

class MainWindow(wx.Frame):
        def __init__(self,parent,id,title):
                wx.Frame.__init__(self,parent,id,title,size=(200,100))
                self.control = wx.TextCtrl(self,1,style=wx.TE_MULTILINE)
                self.CreateStatusBar() #adds a status bar to the bottom
                #Menu setup
                filemenu = wx.Menu()
                filemenu.Append(wx.ID_ABOUT,"&About","Info about the program")
                filemenu.AppendSeparator()
                filemenu.Append(wx.ID_EXIT,"E&xit","Terminate the program.")
                #Menubar setup
                menuBar = wx.MenuBar()
                menuBar.Append(filemenu,"&File") #add file to the menubar
                self.SetMenuBar(menuBar) #add in the menubar
                # Add events
                wx.EVT_MENU(self,ID_ABOUT,self.OnAbout)

                wx.EVT_MENU(self,ID_EXIT,self.OnExit)

                # Go!
                self.Show(True)
        def OnAbout(self,e):
                print "Show!"
                d = wx.MessageDialog(self,"A sample editor.","About Sample
Ed",wx.OK)
                d.ShowModal()
                d.Destroy()
        def OnExit(self,e):
                print "close!"
                self.Close(True)

app = wx.PySimpleApp()

frame = MainWindow(None,wx.ID_ANY,'Small Ed!')

app.MainLoop()

Daniel Gee wrote:
> I'm trying to learn WxPython with the tutorial:
> http://wiki.wxpython.org/Getting_Started

> But I can't seem to get the example for events to work. I pasted the
> code they had directly into an interpreter and it got a dialog to
> appear and the program was able to close itself, but my own copy won't
> work. As far as I can see, it isn't at all different except for the
> name of the main frame, and so I differ to you for help.

--- code snipped ----

>            #Menu setup
>            filemenu = wx.Menu()
>            filemenu.Append(wx.ID_ABOUT,"&About","Info about the program")

Hi,

make it the following instead.

filemenu.Append(ID_ABOUT,"&About","Info about the program")

>            filemenu.AppendSeparator()
>            filemenu.Append(wx.ID_EXIT,"E&xit","Terminate the program.")

And again make it the following.

filemenu.Append(ID_EXIT,"E&xit","Terminate the program.")

--- code snipped ----

--
Kind Regards,
Anthony Irwin

http://www.irwinresources.com
http://www.makehomebusiness.com
email: anthony at above domains, - www.

On May 30, 11:41 pm, Anthony Irwin <nos@noemailhere.nowhere> wrote:

> Daniel Gee wrote:
> > I'm trying to learn WxPython with the tutorial:
> >http://wiki.wxpython.org/Getting_Started

I'm a wxPython beginner too, but instead of Anthony Irwin's
suggestions, I think you should delete these two lines:

ID_ABOUT=101
ID_EXIT=110

and use:

wx.ID_ABOUT
wx.ID_EXIT

throughout the body of your program.  As far as I can tell, there is
no reason for you to be manually setting your own id's (is there
ever?).  Instead, you can use the ids in the wx module.

In addition, I suggest you never use wx.PySimpleApp().  If you create
your own app class, you can send the error messages to the console.
Instead of always seeing a window that flashes at you briefly and
being left with no clue what went wrong, you can at least see an error
message and a line number in the console.  Here's how you would do
that:

-----------------
import wx

class MyFrame(wx.Frame):
    def __init__(self, mytitle):
        wx.Frame.__init__(self, None, title= mytitle)

class MyApp(wx.App):
    def __init__(self):
        wx.App.__init__(self, redirect=False)

app = MyApp()

window = MyFrame("Testing")
window.Show()

app.MainLoop()

------------------

By setting redirect=False in wx.App.__init__(), the errors will be
sent to the console.

That's so simple I'm embarrassed. I should have noticed the change
from the example before to this one.

It works now, thank you.

On May 31, 1:56 am, 7stud <bbxx789_0@yahoo.com> wrote:

> By setting redirect=False in wx.App.__init__(), the errors will be
> sent to the console.

Hmmm...I just read a note I scribbled in the margin of my book that
says setting redirect=False sends the error messages to the console on
Mac and Windows.  Are you using one of those operating systems?  If
not, what os are you using, and do you get errors messages in the
console when using wx.PySimpleApp()?

Thanks

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc