To anyone: I cannot understand what I am doing wrong in the example below. I would just like to draw a simple rectangle.
Thanks,
Thom
from wxPython.wx import *
ID_ABOUT = 101
ID_EXIT = 102
class MyCanvas(wxScrolledWindow):
def __init__(self, parent, id = -1, size = wxDefaultSize):
wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
self.maxWidth = 1000
self.maxHeight = 1000
self.SetBackgroundColour("WHITE")
self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
#self.buffer = wxEmptyBitmap(self.maxWidth, self.maxHeight)
#dc = wxBufferedDC(None, self.buffer)
dc = wxClientDC(self) #, self.buffer)
#dc.SetBackground(wxBrush(self.GetBackgroundColour()))
#dc.Clear()
dc.BeginDrawing()
dc.SetPen(wxPen('RED',3))
dc.DrawRectangle(5, 5, 200, 200)
dc.EndDrawing()
class MyFrame(wxFrame):
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, ID, title,wxDefaultPosition, wxSize(400, 300))
#Status Bar Items
self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
#Create Menu Items
menu = wxMenu()
menu.Append(ID_ABOUT, "&About","More information about this program")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Terminate the program")
# Create the menu bar
menuBar = wxMenuBar()
menuBar.Append(menu, "&File");
self.SetMenuBar(menuBar)
# Create the scrolled window
canvas = MyCanvas(self)
#Event Handlers
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.TimeToQuit)
#Event Methods
def OnAbout(self, event):
dlg = wxMessageDialog(self, "This sample program shows off\n"
"frames, menus, statusbars, and this\n"
"message dialog.",
"About Me", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
self.SetStatusText("This is the statusbar")
def TimeToQuit(self, event):
self.Close(true)
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1, "Thom's Simple Application")
frame.Show(true)
self.SetTopWindow(frame)
return true
app = MyApp(0)
app.MainLoop()