【问题标题】:wxPyDeprecationWarning in Python 3.5Python 3.5 中的 wxPyDeprecationWarning
【发布时间】:2017-01-25 17:38:36
【问题描述】:

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

test_direct_svg.py:20:wxPyDeprecationWarning:使用已弃用的类。 请改用控制。 wx.PyControl.init(self, parent, id, pos, 大小、样式、验证器、名称)

如何在 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

标签: python wxpython


【解决方案1】:

错误意味着您必须在所有地方使用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()

【讨论】:

  • 目前只是一个警告,所以“必须”可能有点强。但它警告你它最终会被删除,所以“应该”是合适的。
猜你喜欢
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
  • 2017-04-21
  • 2019-07-26
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
相关资源
最近更新 更多