steve2
December 19, 2013, 11:49pm
1
Is it a good idea to add notebook pages with a for loop, each panel will use same variable when creating panels, such as
class NoteBook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style= wx.BK_DEFAULT)
pages = ["page1","page2","page3"]
for page in pages:
main_panel = wx.Panel(self)
self.AddPage(main_panel, page)
notebook_page_sizer = wx.BoxSizer()
notebook_page_sizer.Add(main_panel, 1, wx.EXPAND)
self.SetSizer(notebook_page_sizer)
Above all pages will use “main_panel ” variable.Will it create any problems?
Robin
December 20, 2013, 11:00pm
2
steve wrote:
Is it a good idea to add notebook pages with a for loop, each panel will
use same variable when creating panels, such as
class NoteBook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style= wx.BK_DEFAULT)
pages = ["page1","page2","page3"]
for page in pages:
main_panel = wx.Panel(self)
self.AddPage(main_panel, page)
notebook_page_sizer = wx.BoxSizer()
notebook_page_sizer.Add(main_panel, 1, wx.EXPAND)
self.SetSizer(notebook_page_sizer)
Above all pages will use "*main_panel*" variable.Will it create any
problems?
No, just keep in mind that you can't later use main_panel to access any of the pages except for the last one added. However you can use self.GetPage(n) to get them later if you need them.
···
--
Robin Dunn
Software Craftsman