By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,799 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,799 IT Pros & Developers. It's quick & easy.

How to add canvases to a sizer and refresh the parent frame?

Jory R Ferrell
P: 62
I am using wxPython. I need to be able to add and remove panels/canvases on demand, but I don't know how to refresh the entire parent frame (the base starting window). I tried fooling with the Full_Repaint option, but got no where. The method I am using, to add and (hopefully) refresh the frame, Add_Canvas(), starts at line 50.

Expand|Select|Wrap|Line Numbers
  1. canvas_List = [Cone_Canvas, CubeCanvas]
  2.  
  3. class MainWindow(wx.Frame):
  4.     def __init__(self, parent = None, id = -1, title = "PyOpenGL Example 1"):
  5.         # Init
  6.         wx.Frame.__init__(
  7.                 self, parent, id, title, size = (400,200),
  8.                 style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
  9.         )
  10.  
  11.         # TextCtrl
  12.         # self.control = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
  13.  
  14.         #self.control = ConeCanvas(self)
  15.  
  16.         box = wx.BoxSizer(wx.HORIZONTAL)
  17.  
  18.     for canvas in canvas_List:
  19.         box.Add(canvas(self), 1, wx.EXPAND)
  20.  
  21.  
  22.         self.SetAutoLayout(True)
  23.         self.SetSizer(box)
  24.         self.Layout()
  25.  
  26.         # StatusBar
  27.         self.CreateStatusBar()
  28.  
  29.         # Filemenu
  30.         filemenu = wx.Menu()
  31.  
  32.         # Filemenu - About
  33.         menuitem = filemenu.Append(-1, "Add Canvas", "Add a Canvas")
  34.         self.Bind(wx.EVT_MENU, self.Add_Canvas, menuitem) # here comes the event-handler
  35.         # Filemenu - Separator
  36.         filemenu.AppendSeparator()
  37.  
  38.         # Filemenu - Exit
  39.         menuitem = filemenu.Append(-1, "E&xit", "Terminate the program")
  40.         self.Bind(wx.EVT_MENU, self.OnExit, menuitem) # here comes the event-handler
  41.  
  42.         # Menubar
  43.         menubar = wx.MenuBar()
  44.         menubar.Append(filemenu,"&File")
  45.         self.SetMenuBar(menubar)
  46.  
  47.         # Show
  48.         self.Show(True)
  49.  
  50. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
  51.  
  52.     # What do I call(or can I call anything at all?) to
  53.     #    repaint the entire frame? 
  54.  
  55.     def Add_Canvas(self,event):
  56.         canvas_List.append(Cube_Canvas)
  57.         Repaint_Frame() # <---- pseudo....
  58.  
  59. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
  60.  
  61.     def OnExit(self,event):
  62.         self.Close(True)  # Close the frame.
  63.  
Jun 9 '12 #1

✓ answered by dwblas

I do not use Wx but know that it does have a Refresh() function. Try Google for more info.

Share this Question
Share on Google+
3 Replies

Expert 100+
P: 626
I do not use Wx but know that it does have a Refresh() function. Try Google for more info.
Jun 10 '12 #2

Jory R Ferrell
P: 62
I already tried it. Nothing happened.
Jun 11 '12 #3

Jory R Ferrell
P: 62
Nevermind....it was a namespace conflict. I had to rename the sizer, dubbed 'box', as 'self.box'. The window was refreshing without problem, but since nothing was actually being appended to the sizer, there was no visible result to confirm the update of the window and I assumed it wasn't occurring. :P But yeh...it does work. Thanks.
Jun 11 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.