Python 3.5 中的 wxPyDeprecationWarning

wxPyDeprecationWarning in Python 3.5

在 Python 2.7 中工作正常 尝试在 Python 3.5 中使用 wx.PyControl 并收到警告:

test_direct_svg.py:20: wxPyDeprecationWarning: Using deprecated class. Use Control instead. wx.PyControl.init(self, parent, id, pos, size, style, validator, name)

如何在 init 中使用 Control?

Python 我正在执行的代码:

import wx

class ComponentFrame(wx.Frame):
    def __init__(self, parent, id, title, pos, size):
        wx.Frame.__init__(self, parent, id, title, pos, size)

        self.panel = wx.Panel(self)
        vbox = wx.BoxSizer(wx.HORIZONTAL)
        component = SvgComponent(self.panel)
        vbox.Add(component, 1, wx.EXPAND | wx.ALL, 10)
        self.panel.SetSizer(vbox)

class SvgComponent(wx.PyControl):
    def __init__(self, parent, label="",
                 id=wx.ID_ANY,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=wx.NO_BORDER, validator=wx.DefaultValidator,
                 name="LoggerUI"):

        wx.PyControl.__init__(self, parent, id, pos, size, style, validator, name)


if __name__ == '__main__':
        app = wx.App()
        frame = ComponentFrame(None, wx.ID_ANY, 'test rsvg', (200, 200), (400, 400))
        app.MainLoop()      

错误意味着您必须在所有地方使用 wx.Control 而不是 wx.PyControl

顺便说一句:别忘了frame.Show()

import wx

class ComponentFrame(wx.Frame):

    def __init__(self, parent, id, title, pos, size):
        wx.Frame.__init__(self, parent, id, title, pos, size)

        self.panel = wx.Panel(self)
        vbox = wx.BoxSizer(wx.HORIZONTAL)
        component = SvgComponent(self.panel)
        vbox.Add(component, 1, wx.EXPAND | wx.ALL, 10)
        self.panel.SetSizer(vbox)

class SvgComponent(wx.Control):

    def __init__(self, parent, label="",
                 id=wx.ID_ANY,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=wx.NO_BORDER, validator=wx.DefaultValidator,
                 name="LoggerUI"):

        wx.Control.__init__(self, parent, id, pos, size, style, validator, name)


if __name__ == '__main__':
    app = wx.App()
    frame = ComponentFrame(None, wx.ID_ANY, 'test rsvg', (200, 200), (400, 400))
    frame.Show()
    app.MainLoop()