You are almost there. These 2 small changes should help
1. Call Refresh() in ZoneNew.__init__, i.e.
class ZoneNew(wxWindow):
def __init__(self, parent, ID_ZONENEW, pos=wxDefaultPosition,
size=wxDefaultSize):
wxWindow.__init__(self, parent, ID_ZONENEW, pos, size)
self.SetBackgroundColour(wxNamedColour('red'))
self.Refresh()
2. Rather than let the size and position of the ZoneNew window be defaulted,
pass in the position and size of zonePlace when button1 is clicked:
def onButton1(self, event):
self.zonePlace = ZoneNew(self, ID_ZONENEW,
self.zonePlace.GetPosition(),
self.zonePlace.GetSize())
···
-----Original Message-----
From: Carole Valentin [mailto:carole@autosim.no]
Sent: Wednesday, October 31, 2001 6:21 AM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] Problems to modify a window
Hello,
I need some help to solve a little problem...
I would like to make a frame with 2 buttons on the top ("Button 1" and
"Button 2") and with a white zone below them (the white zone is
resizable with the window). When I click on the "Button 1", I want to
modify the white zone, for instance: change the zone colour so that the
zone becomes red (it might be others possibilities in the future).
What I have done does not work: I get a little red square at the top
left corner of the frame and the zone contents does not change.
You will find my program just below.
Thank you for your help!
Carole.
#--------------------------------------------------------------------
from wxPython.wx import *
ID_BUTTON1 = 10
ID_BUTTON2= 20
ID_FRAME = 110
ID_ZONE = 120
ID_ZONENEW = 130
#------------------------
class ZoneNew(wxWindow):
def __init__(self, parent, ID_ZONENEW, pos=wxDefaultPosition,
size=wxDefaultSize):
wxWindow.__init__(self, parent, ID_ZONENEW, pos, size)
self.SetBackgroundColour(wxNamedColour('red'))
#------------------------
class Zone(wxWindow):
def __init__(self, parent, ID_ZONE, pos=wxDefaultPosition,
size=wxDefaultSize):
wxWindow.__init__(self, parent, ID_ZONE, pos, size)
self.SetBackgroundColour(wxNamedColour('white'))
#------------------------
def makeBox(win):
box = wxBoxSizer(wxVERTICAL)
box1 = wxBoxSizer(wxHORIZONTAL)
box1.AddMany([(wxButton(win, ID_BUTTON1, "Button 1"), 0, wxALL, 20),
(wxButton(win, ID_BUTTON2, "Button 2"), 0, wxALL, 20)
])
box.Add(box1, 0, wxEXPAND)
win.zonePlace = Zone(win, ID_ZONE)
box.Add(win.zonePlace, 1, wxEXPAND)
return box
#------------------------
class MyFrame(wxFrame):
def __init__(self, parent):
wxFrame.__init__(self, parent, ID_FRAME, "My Frame",
wxDefaultPosition, wxSize(300, 150))
self.sizer = makeBox(self)
self.SetAutoLayout(true)
self.SetSizer(self.sizer)
EVT_BUTTON(self, ID_BUTTON1, self.onButton1)
def onButton1(self, event):
self.zonePlace = ZoneNew(self, ID_ZONENEW)
#------------------------
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL)
frame.Show(true)
self.SetTopWindow(frame)
return true
#------------------------
app = MyApp(0)
app.MainLoop()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users