在wxFrame中绘制,如何传递参数?

2024-04-20 04:49:33 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,考虑http://matplotlib.org/examples/user_interfaces/embedding_in_wx4.html中的代码。但是,假设我需要传递振幅作为参数,我怎么能做到呢?如果修改App类声明

class App(wx.App):
    def __init__(self,amplitude):
        wx.App.__init__(self)
        self.arg=amplitude
    def OnInit(self):
        '''Create the main window and insert the custom frame'''
        frame = CanvasFrame(self.arg)
        frame.Show(True)

        return True

如果我修改CanvasFrame.\uqinit_u(),以获取一个参数,这就行不通了。在

谢谢你的帮助!在


Tags: theorgselftrueapphttp参数matplotlib
1条回答
网友
1楼 · 发布于 2024-04-20 04:49:33

我不明白为什么传递给CanvasFrame的参数不起作用。链接的mpl wx4演示程序修改如下,并且可以工作: 编辑II:您的错误是交换wx.App.__init__(self)和{}。在您的例子中,当调用App.OnInit(…)时,self.args尚未设置。在

class CanvasFrame(wx.Frame):    
    def __init__(self, amplitude):
        wx.Frame.__init__(self, None, -1, …
        …
        self.amplitude = amplitude
        …
        # now use the amplitude
        s = sin(2*pi*t) * self.amplitude

在派生的App中:

^{pr2}$

也许让一个CanvasFrameApp不能再初始化为wx.Frame(父项和标题硬编码到object中)不是一个好主意,但这是另一个故事。在

编辑:扩展示例,完全满足OP的问题(自顶向下传递的参数)

相关问题 更多 >