wxpython 链接并打开新窗口应用程序

发布于 2024-10-21 01:11:21 字数 1022 浏览 5 评论 0原文

我有一个对话框应用程序和一个框架应用程序(两个文件),我希望它们彼此交互。

我想单击对话框应用程序上的按钮,它将关闭对话框应用程序并打开我的框架应用程序。知道我该如何实现这一目标吗?

我的对话框应用程序非常简单,看起来像这样

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()

谢谢

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.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()

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油焖大侠 2024-10-28 01:11:22

您需要在 Dialog 应用程序周围创建一个框架,这样它就不会表现得很奇怪。没有人说过您必须显示它:

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) 以返回已知值。现在,在某些时候,您必须弄清楚如何彻底销毁您的应用程序,但我认为您可以从这里获得它!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文