我正在使用wxpython進行GUI,我是python的新手,..我做了一個GUI說大型機,它有一個按鈕,當我點擊它彈出一個新框架說兒童框架。當我們打開子框架時如何隱藏大型機
我想知道如何在子框架打開時隱藏大型機以及如何從子框架返回到大型機。
提前盼望好建議
感謝
我正在使用wxpython進行GUI,我是python的新手,..我做了一個GUI說大型機,它有一個按鈕,當我點擊它彈出一個新框架說兒童框架。當我們打開子框架時如何隱藏大型機
我想知道如何在子框架打開時隱藏大型機以及如何從子框架返回到大型機。
提前盼望好建議
感謝
我用的PubSub做這樣的事情。我實際上在這裏寫了一個關於這個過程的教程:http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/
如果你想從子框架中終止程序,那麼你需要發送一個消息回到父框架告訴關閉/銷燬自己。您可以嘗試將對父框架的引用傳遞給孩子並將其關閉,但是我懷疑這會導致錯誤,因爲它會在孩子之前摧毀父母。
+1我通常通過發送家長的引用給孩子來解決兩個幀之間的通信問題,如我的答案中所示。但我明白,pubsub是學習的工具,因爲它是管理與父母溝通的整齊複雜的孩子系統的正確方式。 – joaquin
使用隱藏和顯示方法。
在這個例子中,家長和孩子幀按下按鈕時互相替代:
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.button = wx.Button(self, wx.ID_ANY, "Parent")
self.child = None
self.Bind(wx.EVT_BUTTON, self.onbutton, self.button)
self.SetTitle("myframe")
def onbutton(self, evt):
if not self.child: # if the child frame has not been created yet,
self.child = Child(self) # create it, making it a child of this one (self)
self.child.Show() # show the child
self.Hide() # hide this one
class Child(wx.Frame):
def __init__(self, parent, *args, **kwds): # note parent outside *args
wx.Frame.__init__(self, parent, *args, **kwds)
self.button = wx.Button(self, wx.ID_ANY, "Child")
self.parent = parent # this is my reference to the
# hidden parent
self.Bind(wx.EVT_BUTTON, self.onbutton, self.button)
self.SetTitle("child")
def onbutton(self, evt):
self.parent.Show() # show the parent
self.Hide() # hide this one
if __name__ == "__main__":
app = wx.PySimpleApp(0)
frame = MyFrame(None, wx.ID_ANY, "")
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
如何終止這個? – sooraj1990
如果它回答你的原始問題,你應該投票和/或選擇答案。就這些。將來,其他海報可以在同一頁面上產生新的答案或編輯或修改其他答案。 – joaquin
請幫我找回答 – sooraj1990