0
我在學習wxpython.I閱讀文檔,並在與它一起玩之後,現在我創建了一個包含一些面板的小應用程序。在一個面板上,我創建了一個登錄頁面。 OnSubmit
的登錄面板,我想切換到另一個面板。我不知道該怎麼做。這裏是我的代碼(ScreenGrab可以幫助你): (不需要的功能和類定義這裏沒有顯示):切換到另一個面板wxpython
Toolbook_Demo.py
class ToolbookDemo(wx.Toolbook) :
def __init__(self, parent) :
print ""
wx.Toolbook.__init__(self, parent, wx.ID_ANY, style=
wx.BK_DEFAULT
#wx.BK_TOP
#wx.BK_BOTTOM
#wx.BK_LEFT
#wx.BK_RIGHT
)
# Make an image list using the LBXX images
il = wx.ImageList(32, 32)
for x in range(4) :
imgObj = getattr(images, 'LB%02d' % (x+1))
bmp = imgObj.GetBitmap()
il.Add(bmp)
self.AssignImageList(il)
imageIdGenerator = getNextImageID(il.GetImageCount())
panellogin = userlogin.TabPanel(self)
print panellogin.Hide()
notebookPageList = [ (userlogin.TabPanel(self), 'Login'),
(panelTwo.TabPanel(self), 'Panel Two'),
(panelThree.TabPanel(self), 'Panel Three'),
(panelOne.TabPanel(self), 'Home')]
imID = 0
for page, label in notebookPageList :
self.AddPage(page, label, imageId=imageIdGenerator.next())
imID += 1
# An undocumented method in the official docs :
self.ChangeSelection(0) # Select and view this notebook page.
# Creates no events - method SetSelection does.
self.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGING, self.OnPageChanging)
self.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGED, self.OnPageChanged)
userlogin.py
import wx
class TabPanel(wx.Panel) :
""" This will be [inserted into] the first notebook tab. """
def __init__(self, parent) :
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
sizer = wx.FlexGridSizer(rows=3, cols=2, hgap=5, vgap=15)
# Username
self.txt_Username = wx.TextCtrl(self, 1, size=(150, -1))
lbl_Username = wx.StaticText(self, -1, "Username:")
sizer.Add(lbl_Username,0, wx.LEFT|wx.TOP| wx.RIGHT, 50)
sizer.Add(self.txt_Username,0, wx.TOP| wx.RIGHT, 50)
# Password
self.txt_Password = wx.TextCtrl(self, 1, size=(150, -1), style=wx.TE_PASSWORD)
lbl_Password = wx.StaticText(self, -1, "Password:")
sizer.Add(lbl_Password,0, wx.LEFT|wx.RIGHT, 50)
sizer.Add(self.txt_Password,0, wx.RIGHT, 50)
# Submit button
btn_Process = wx.Button(self, -1, "&Login")
self.Bind(wx.EVT_BUTTON, self.OnSubmit, btn_Process)
sizer.Add(btn_Process,0, wx.LEFT, 50)
self.SetSizer(sizer)
def OnSubmit(self, event):
UserText = self.txt_Username.GetValue()
PasswordText = self.txt_Password.GetValue()
if authentcated(UserText, PasswordText):
#Switch to another panel
#Hide login panel until current session expires
#Show another panels only
感謝您的回覆。你是對的。但是,我無法切換到另一個頁面,點擊第一個面板中顯示的登錄按鈕 – trex 2014-11-03 06:57:33