trying to have a new panel created when clicking a button in wxpython rookie
I would like to have a new panel open from my mainPanel so that I can put text boxes to enter data and have a back button to go back to the mainPanel. Here is my code.
#!/usr/bin/env python
import wx
class secPanel(wx.Panel):
def __init__(self):
wx.Panel.__init__(self)
self.Show(true)
class Frame(wx.Frame):
"""subclassing wx.Frame for app templates with file->quit coded"""
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuItem = menu1.Append(-1, "&Exit")
menuBar.Append(menu1, "&File")
mainPanel = wx.Panel(self, wx.ID_ANY)
strainEntry = wx.Button(mainPanel, label="Enter Strain", pos=(900,100),
size=(100,100))
uploadPic = wx.Button(mainPanel, label="Upload Pics", pos=(900,150),
size=(100,100))
editStrain = wx.Button(mainPanel, label="Edit Strain", pos=(900开发者_如何学Go,200),
size=(100,100))
self.Bind(wx.EVT_BUTTON, self.strButtonClick, strainEntry)
#self.SetToolTip(wx.ToolTip("Click to Enter Strain"))
def strButtonClick(self,event):
newPanel = secPanel(self)
with my app.py
import wx
from FrmTem import *
import FrmTem
class App(wx.App):
def OnInit(self):
self.frame = Frame("Growtistics", (40,40),(1080,680))
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main():
app = App()
app.MainLoop()
if __name__ == '__main__':
main()
This will probably get you part or all of the way there:
http://www.blog.pythonlibrary.org/2010/06/16/wxpython-how-to-switch-between-panels/
You might also want to look at the various Notebook widgets that wxPython includes or perhaps the Wizard.
By the way, there is an official wxPython mailing list that is great for learning about wxPython and asking questions on: http://groups.google.com/group/wxpython-users/topics?pli=1
精彩评论