Beginner Needs Help

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

Hi Thom

I am a newbie too. If your question is 'why doesn't this run?' then try
this. Your program runs for me - after a couple of indentation changes and I
also took a couple of split lines and made them one - be really careful
about indentation here as well. Rather than put it in the text, I hope I can
post an attachment.

If I haven't understood your question and it is a matter of behaviour, then
let me know.

Mike

rectangle.py (2.34 KB)

···

----- Original Message -----
From: "Thom Ives" <twives@cableone.net>
To: <wxpython-users@lists.wxwindows.org>
Sent: Sunday, October 26, 2003 8:06 PM
Subject: [wxPython-users] Beginner Needs Help

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Thom Ives wrote:

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

Thom;

I'm using Linux, and see the problem too. I believe the problem occurs because you're rendering your rectangle prior to showing the frame. However, since the drawing isn't being refreshed when the screen is shown, you see nothing. I tried putting the drawing code into a separate method and adding a draw menu to invoke it. Once I did that, the square was being drawn.

Phrodo