wxpython link and open new window apps
I have one dialog app and one frame app (two files) and I want them to interact with each other.
I would like to to click a button on my dialog app and it will close the dialog app and open my frame app. Any idea how I can achieve this?
my dialog app is very simple and looks something like this
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.idk开发者_开发技巧2, 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()
Thanks
You'll want to create a frame around your Dialog app so it doesn't act strangely. No one ever said you have to Show it:
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()
In your idk1 method, call self.EndModal(1) to return a known value. Now at some point you'll have to figure out how to cleanly Destroy your apps, but I think you can get it from here!
精彩评论