wxPython - 如何获取顶部框架或应用程序对象

发布于 2024-09-19 19:56:55 字数 649 浏览 2 评论 0原文

我对如何在应用程序中获取顶部框架有点困惑。我以通常的方式开始我的应用程序

class AppFrame(ClientGUI.MyFrame): #ClientGUI.MyFrame generated by wxformbuilder. 
def __init__(self):
    # create some panels. 
    # Create some object classes that invoke objects of other classes.
    # .. do other stuff ... 

if __name__ == '__main__':
    app = wx.App(0)
    frame = AppFrame()
    frame.Show()
    app.MainLoop()

鉴于我有一个深度嵌套的类调用序列,我希望调用层次结构底部的一个对象能够访问应用程序中的某个面板(基本上将一些 gui 内容放入该面板中) )。我能想到的一种方法是将应用程序对象(“self”)作为参数包含到我的对象调用序列中,以便最后一个对象可以访问应用程序对象。但这似乎相当复杂,因为所有中间对象都不需要访问应用程序。

有没有一种干净的方法来访问应用程序对象?另外,我到底想访问什么——“框架”对象还是“应用程序”对象?我不确定这两个对象之间的区别。

I am little confused about how to get the top frame in an application. I start off my application with the usual

class AppFrame(ClientGUI.MyFrame): #ClientGUI.MyFrame generated by wxformbuilder. 
def __init__(self):
    # create some panels. 
    # Create some object classes that invoke objects of other classes.
    # .. do other stuff ... 

if __name__ == '__main__':
    app = wx.App(0)
    frame = AppFrame()
    frame.Show()
    app.MainLoop()

Given that I have a deeply nested class-invocation sequence, I would like one of my objects in the bottom of the invocation hierarchy to access some panel in the application (basically put some gui stuff into that panel). One way I could think of is to include the application object ('self') as parameter into my object invocation sequence so that the last object has access to the application object. But this seems rather convoluted given that all the intermediate objects don't need access to the application.

Is there a clean way to access the application object? Also, what exactly do I want to access -- the "frame" object or the "app" object ? I'm not sure of the difference between these two objects.

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

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

发布评论

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

评论(1

心欲静而疯不止 2024-09-26 19:56:55

我通常不建议这样做,但您想要的方法可能是:

topFrame = wx.GetTopLevelParent()

如果您需要类间通信,我通常使用 PubSub。无论如何,我希望有帮助!

I don't usually recommend doing it that way, but the method you want is probably:

topFrame = wx.GetTopLevelParent()

If you need inter-class communication, I usually use PubSub. Anyway, I hope that helps!

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