2011-03-10 65 views
0

我有一個對話框應用程序和一個框架應用程序(兩個文件),我希望它們互相交互。wxpython鏈接並打開新窗口應用程序

我想單擊我的對話框應用程序上的按鈕,它將關閉對話框應用程序並打開我的框架應用程序。任何想法如何我可以實現這一目標?

我的對話框的應用程序非常簡單,看起來像這樣

class ThisClass(wx.Dialog): 
    def __init__(self, parent, id, title): 
     wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y)) 

     wx.Button(self, 1, 'Start Monitoring', (50, 20), (120,-1)) 
     wx.Button(self, 2, 'View Data', (50, 70), (120, -1)) 
     wx.Button(self, 3, 'Close', (50, 120), (120, -1)) 


     self.Bind(wx.EVT_BUTTON, self.idk1, id=1) 
     self.Bind(wx.EVT_BUTTON, self.idk2, id=2) 
     self.Bind(wx.EVT_BUTTON, self.clickClose, id=3) 

     self.Centre() 
     self.ShowModal() 

    def idk1(self,event): 
     #i want to launch another app here if 
     #this (Start Monitoring) button is pressed 

    def idk2(self, event): 
     self.Close(True) 

    def clickClose(self, event): 
     self.Close(True) 

app = wx.App(0) 
MyButtons(None, -1, 'buttons.py') 
app.MainLoop() 

感謝

回答

1

你要創建一個在你的應用程序對話的框架,因此不會奇怪行爲。從來沒有人說你要顯示它:

class ThisFrame(wx.Frame): 
    def __init__(self, parent, title): 
     wx.Frame.__init__(self, parent, title=title, size=(0, 0)) 
     dlg = ThisClass(self, -1, "buttons.py") 

     if dlg.ShowModal() == 1: 
      from otherfile import MyFrame 
      mf = MyFrame(self, "MyFrame") 
      mf.Show() 

app = wx.App(0) 
frame = ThisFrame(None, 'ThisFrame') 
app.MainLoop() 

在你idk1方法,調用self.EndModal(1)返回一個已知值。現在,在某些時候,你必須弄清楚如何幹淨地銷燬你的應用程序,但我認爲你可以從這裏得到它!

+0

你好,謝謝你的回覆。我做了類似於你的建議,我設法讓我的MyFrame(從其他文件)彈出,但我無法與它互動。小部件不能工作等 – lamba 2011-03-10 10:58:50

+0

在你的其他文件中,創建一個函數app = MyFrame(0)和app.MainLoop(),然後調用該函數。這對我有效。 – Jake 2011-03-10 15:22:49