2017-01-25 39 views
0

在Python 2.7 工程確定試圖在Python 3.5使用wx.PyControl並得到警告:wxPyDeprecationWarning在Python 3.5

test_direct_svg.py:20:wxPyDeprecationWarning:使用過時類。 改爲使用控制。 wx.PyControl。 初始化(自我,父母,ID,POS, 大小,樣式,驗證,名稱)

如何在初始化使用控制?

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

讀取錯誤信息 - 這意味着你必須使用'wx.Control',而不是'wx.PyControl' – furas

回答

3

錯誤意味着你必須在所有地方使用wx.Control而不是wx.PyControl

BTW:不要再忘記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() 
+0

它目前只是一個警告,所以「有到「可能會有點強大。但它警告你它最終會被刪除,所以「應該」是適當的。 – RobinDunn