【发布时间】:2016-11-25 16:51:14
【问题描述】:
我在Python 和wxPython 都是新手。无论如何,在按照官方教程解释如何做一个基本的文本编辑器之后,我决定继续写一个真正的文本编辑器。
现在,我的文本编辑器包含一个 MainWindow(继承自 wx.Frame),而 Notebook(继承自 wx.Notebook)又包含几个 标签(继承自wx.Panel的自定义类)。
如果我没有误会的话,wxPython 中的事件可以通过Bind() 函数检测并绑定到特定对象。
这是我的自定义面板类:
class TabContent(wx.Panel) :
def __init__(self, parent) :
# Calls the constructor for wx.Panel
wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
# Creates a vertical sizer
sizer = wx.BoxSizer(wx.VERTICAL)
# Creates an empty multiline wx.TextCtrl
textArea = wx.TextCtrl(self, style = wx.TE_MULTILINE)
# Adds the text area to the sizer
sizer.Add(textArea, 1, wx.EXPAND | wx.ALL, 2)
# Sets the previously created sizer as this panel's sizer
self.SetSizer(sizer)
# Sets up events
self.Bind(wx.EVT_RIGHT_DOWN, self.onMouseLeftClicked)
def onMouseLeftClicked(self, event) :
print("Left button of the mouse was clicked\n")
我希望能够检测选项卡本身的右键单击(例如,我可以打开一个菜单或打印一些东西来测试 wxPython 函数)。但是,用鼠标单击不会打印任何内容。知道为什么吗?
顺便说一句,我在 ArchLinux 上,使用 PyCharm Community Edition 2016.2.3、Python 3.5.2 和 wxpython 3.0.2。
【问题讨论】:
标签: python-3.x event-handling wxpython mouseevent