gpt4 book ai didi

python - Aui笔记本,事件发生在哪里

转载 作者:太空宇宙 更新时间:2023-11-03 19:39:53 26 4
gpt4 key购买 nike

如何找出事件发生在哪个 AuiNotebook 页面?

编辑:对此表示抱歉。这是一个代码示例。如何找到笔记本页面从女巫那里点击了鼠标?

#!/usr/bin/python

#12_aui_notebook1.py

import wx
import wx.lib.inspection

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)

self.nb = wx.aui.AuiNotebook(self)

self.new_panel('Pane 1')
self.new_panel('Pane 2')
self.new_panel('Pane 3')

def new_panel(self, nm):
pnl = wx.Panel(self)
self.nb.AddPage(pnl, nm)
self.sizer = wx.BoxSizer()
self.sizer.Add(self.nb, 1, wx.EXPAND)
self.SetSizer(self.sizer)

pnl.Bind(wx.EVT_LEFT_DOWN, self.click)

def click(self, event):
print 'Mouse click'
#How can I find out from witch page this click came from?


class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, '12_aui_notebook1.py')
frame.Show()
self.SetTopWindow(frame)
return 1

if __name__ == "__main__":
app = MyApp(0)
# wx.lib.inspection.InspectionTool().Show()
app.MainLoop()

奥尔詹·佩特森

最佳答案

对于鼠标单击,您可以假设当前选定的页面是获得单击的页面。我在你的代码中添加了几行。查看评论

def new_panel(self, nm):
pnl = wx.Panel(self)
# just to debug, I added a string attribute to the panel
# don't you love dynamic languages? :)
pnl.identifierTag = nm
self.nb.AddPage(pnl, nm)
self.sizer = wx.BoxSizer()
self.sizer.Add(self.nb, 1, wx.EXPAND)
self.SetSizer(self.sizer)

pnl.Bind(wx.EVT_LEFT_DOWN, self.click)

def click(self, event):
print 'Mouse click'
# get the current selected page
page = self.nb.GetPage(self.nb.GetSelection())
# notice that it is the panel that you created in new_panel
print page.identifierTag

关于python - Aui笔记本,事件发生在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/578800/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com