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 个回答
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) 来返回一个已知的值。接下来,你需要想办法干净利落地关闭你的应用,不过我觉得你应该能从这里继续搞定!