0
我在Python
和wxPython
上都很新颖。无论如何,在遵循官方教程,他们解释了如何做一个基本的文本编辑器之后,我决定继续编写一个真正的文本编辑器。如何检测鼠标点击自定义wx.Panel?
现在,我的文本编辑器由一个MainWindow
(从wx.Frame
继承),又包含一个Notebook
(从wx.Notebook
继承),又包含几个标签(自定义类从wx.Panel
继承)的。
如果我没有误解,可以通过Bind()
函数检测wxPython
中的事件并将其绑定到特定对象。
这里是我的自定义面板类:
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社区版2016.2.3,Python 3.5.2和wxpython 3.0.2。