【发布时间】:2011-12-02 11:19:33
【问题描述】:
我知道 Python 与 Java 不同,它支持继承。但是一个用户类可以毫无问题地继承几个 wxPython 类吗? (wxPython 的设计允许这样做吗?)
提前谢谢你
我正在使用 wxPython 2.8 绑定在 Xubuntu 11.04 下编码
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 检测到“wxControl *”类型的内存泄漏,没有找到析构函数。 回溯(最近一次通话最后): 文件“/home/laurent/Documents/Programmation/Projets/Python/SourcesDeTest/ReactiveSquare.py”,第 31 行,在 框架 = MainFrame() init 中的文件“/home/laurent/Documents/Programmation/Projets/Python/SourcesDeTest/ReactiveSquare.py”,第 19 行 square1 = 正方形(面板) init 中的文件“/home/laurent/Documents/Programmation/Projets/Python/SourcesDeTest/ReactiveSquare.py”,第 10 行 wx.Control.init(自身,父级) init 中的文件“/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py”,第 11718 行 self._setOORInfo(self) _setOORInfo 中的文件“/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py”,第 3887 行 args[0].this.own(False) getattr 中的文件“/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py”,第 14606 行 引发 PyDeadObjectError(self.attrStr % self._name) wx._core.PyDeadObjectError: Square 对象的 C++ 部分已被删除,不再允许属性访问。 脚本终止。
【问题讨论】:
标签: inheritance wxpython