2014-10-26 18 views
0

我想要做的實際上是我想要訪問所有我創建的框架。在這裏我創建了3個框架 - 「MainFrame」,「FirstFrame」,「SecondFrame」。因此,我想打開,關閉或者最小化任何我想要的幀。是否可以關閉「MainFrame」而不關閉其他幀?我已經創建了一個程序。但是,在打開其他幀而不關閉它們之後,我無法訪問MainFrame。如何在打開另一個框架後訪問wxPython中的MainFrame?

這裏是我的代碼 -

import wx 

class MainFrame(wx.Frame): 
    def __init__(self,parent,id): 
     wx.Frame.__init__(self,parent,id,"Main WIndow",size=(600,400)) 
     panel=wx.Panel(self) 

     self.button1=wx.Button(panel,label='First Window',pos=(80,30),size=(130,50)) 
     self.button2=wx.Button(panel,label='Second Window',pos=(80,100),size=(130,50)) 
     self.Bind(wx.EVT_BUTTON,self.evt1,self.button1) 
     self.Bind(wx.EVT_BUTTON,self.evt2,self.button2) 


    def evt1(self,parent): 
     frame=FirstFrame(self,-1) 
     frame.Show(True) 
     frame.MakeModal(True) 

    def evt2(self,parent): 
     frame=SecondFrame(self,-1) 
     frame.Show(True) 
     frame.MakeModal(True) 

class FirstFrame(wx.Frame): 
    def __init__(self,parent,id): 
     wx.Frame.__init__(self,parent,id,"First Window",size=(600,400)) 
     self.Bind(wx.EVT_CLOSE, self.on_close) 
    def on_close(self, evt): 
     self.MakeModal(False) 
     evt.Skip() 


class SecondFrame(wx.Frame): 
    def __init__(self,parent,id): 
     wx.Frame.__init__(self,parent,id,"Second Window",size=(600,400)) 
     self.Bind(wx.EVT_CLOSE, self.on_close1) 
    def on_close1(self, evt): 
     self.MakeModal(False) 
     evt.Skip()  

if __name__=='__main__': 
    app=wx.PySimpleApp() 
    frame=MainFrame(None,-1) 
    frame.Show() 
    app.MainLoop() 

回答

1

,因爲你所做的其他窗口莫代爾你不能訪問主窗口,這就是模式的整點,停止一切並等待模態框架之前關閉返回到前一幀。

要在父框架關閉時停止子框架關閉,您需要使它們成爲獨立框架。 要做到這一點,而不是將自己作爲父項,請將None作爲父項。

相關問題