trouble with wxPython intro

Daniel Gee zefria at gmail.com
Wed May 30 23:11:08 EDT 2007


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()




More information about the Python-list mailing list