473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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,1 00))
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()

May 31 '07 #1
4 1198
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.
May 31 '07 #2
On May 30, 11:41 pm, Anthony Irwin <nos...@noemailhere.nowherewrote:
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.

May 31 '07 #3
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.

May 31 '07 #4
On May 31, 1:56 am, 7stud <bbxx789_0...@yahoo.comwrote:
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
May 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: chauhan | last post by:
Hi, I am new to pogramming. I have written a small program which retrieves emails from server, unless all the messages are loaded only then it displays on screen properlely. Whole thing works...
7
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
0
by: andrea valle | last post by:
Hi to all can anyone point me to a wxpython tutorial (something like the Intro to tkinter by Lundh)? Thanks -a-
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
1
by: timothy.williams | last post by:
I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have...
25
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
1
by: PAllen | last post by:
Hi all, I am trying to get rid of a few of my old MS Access applications and move them to PostgreSQL and Python/wxpython. Does anyone have any suggestions on the easiest way to learn to program...
3
by: sgerdan | last post by:
Hi,I'm trying to compile wxpython from source code.But it gives me lots of errors like below. cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++ In...
6
by: shapper | last post by:
Hello, When styling a DIV as follows: <div id="intro" class="Intro">Some intro text</div> Should I use a class: ..Intro {...} Or:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.