wxPython - How to load a different panel into a frame

M

matthiasjanes

Dear all,

I'm very new to wxPython. I'm using the wxglade ide to make a Gui.

question is:

Let's say I have a very simple frame with to menu entrys: LoadPanel1 and LoadPanel2

______________________loadpanel.py_________________________________

#Begin:___Example_Code__

#!/usr/bin/env python
# generated by wxGlade 0.3.3 on Thu Jul 08 20:53:38 2004

import wx

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)

# Menu Bar
self.frame_1_menubar = wx.MenuBar()
self.SetMenuBar(self.frame_1_menubar)
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(10, "LoadPanel1", "LoadPanel1", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(20, "LoadPanel2", "LoadPanel2", wx.ITEM_NORMAL)
self.frame_1_menubar.Append(wxglade_tmp_menu, "Panel")
# Menu Bar end

self.__set_properties()
self.__do_layout()
# end wxGlade

#MANUEL ADDED CODE: Generate Bind Events Funktions

self.Bind(wx.EVT_MENU, self.OnClickLoadPanel1, id=10)
self.Bind(wx.EVT_MENU, self.OnClickLoadPanel2, id=20)

#END MANUEL ADDED CODE: Generate Bind Events Funktions

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.SetSize((400, 300))
# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
self.SetAutoLayout(1)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade


#MANUEL ADDED CODE: Events Funktions
def OnClickLoadPanel1(self, event):
print "LoadPanel1"
# someCode

def OnClickLoadPanel2(self, event):
print "LoadPanel2"
# someCode

#END OF MANUEL ADDED CODE: Events Funktions

# end of class MyFrame


class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
self.SetTopWindow(frame_1)
frame_1.Show(1)
return 1

# end of class MyApp

if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()

# END:___Example_Code__

_______________________________________________________

Now How do I actually load a different Panel when I click the MenuEntries.

Some simple working examples would be really greate.

Thanks Matthias Janes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top