Skip to content

Instantly share code, notes, and snippets.

@jarredkenny
Created January 1, 2012 20:01
Show Gist options
  • Save jarredkenny/1548194 to your computer and use it in GitHub Desktop.
Save jarredkenny/1548194 to your computer and use it in GitHub Desktop.
Creating Tabed Guis - The Right Way
import wx
class Gui(wx.Frame): #create a wx frame object
def __init__ (self, parent=None, *args, **kwarg): #set initial parameters
super(Gui, self).__init__(None, -1, "Example", size = (300, 250)) #pass these paramenters to my wx.Frame object
Notebook = wx.Notebook(self) #creates a notebook which is a child of out wx.Frame
#here is where we get organised, we create a dictionary to reference each tab by name
Tab_By_Name = {
"Chatz" : wx.Panel(Notebook),
"Forumz" : wx.Panel(Notebook),
"Coolz" : wx.Panel(Notebook),
"Anotherz" : wx.Panel(Notebook),
} #we name each tab, and assign it to a Panel object which is a child of our notebook object
for Tab in Tab_By_Name: #now we are going to iterate through our dictionary
Notebook.AddPage(Tab_By_Name[Tab], Tab) #and for each entry, add the panel object to our notebook using the names from our dictionary
#now if we want too call on an tab object, we can use Tab_By_Nam['Tab Name']
if __name__ == "__main__":
#this is some wx init garbage you can ignore
App = wx.App()
Frame = Gui()
Frame.Show()
App.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment