我知道Python和Java不同,它支持继承。但是用户类可以从几个wxPython类继承而没有任何问题? (是否wxPython的设计让这个?)wxPython和多重继承
预先感谢您
我是Xubuntu 11.04之下编码与wxPython的2.8结合
P.S:这是我的尝试。
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import wx
class Square(wx.Panel, wx.Control):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY, size=(60,60), pos=(80,50))
wx.Control.__init__(self, parent)
self.SetBackgroundColour(wx.Colour(0,0,255))
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Reactive square application",
size = (300,200))
panel = wx.Panel(self, wx.ID_ANY)
square1 = Square(panel)
square2 = Square(panel)
square1.Bind(wx.EVT_BUTTON, self.OnSquareClick)
def OnSquareClick(self, event):
dialog = wx.MessageDialog(self, "You clicked on square !!!",
"Hit has been done", wx.OK)
dialog.Show(True)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MainFrame()
frame.Show(True)
app.MainLoop()
这是堆栈跟踪:从多个父类
swig/python detected a memory leak of type 'wxControl *', no destructor found. Traceback (most recent call last): File "/home/laurent/Documents/Programmation/Projets/Python/SourcesDeTest/ReactiveSquare.py", line 31, in frame = MainFrame() File "/home/laurent/Documents/Programmation/Projets/Python/SourcesDeTest/ReactiveSquare.py", line 19, in init square1 = Square(panel) File "/home/laurent/Documents/Programmation/Projets/Python/SourcesDeTest/ReactiveSquare.py", line 10, in init wx.Control.init(self, parent) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 11718, in init self._setOORInfo(self) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3887, in _setOORInfo args[0].this.own(False) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14606, in getattr raise PyDeadObjectError(self.attrStr % self._name) wx._core.PyDeadObjectError: The C++ part of the Square object has been deleted, attribute access no longer allowed. Script terminated.
好吧,我不知道mixin类。我要在Google上搜索一个很好的介绍。因为我认为第二个解决方案(wxPython sub +我自己的类)也很难使其工作 – loloof64