我有一個Notebook
類與一些標籤/頁面(從wx.Panel
繼承)。如何集中一個wx.Notebook頁面時,右鍵點擊它
我目前在Notebook
類中檢測到一個右擊並且一切正常。唯一的問題是,當我右鍵單擊它時,我想將焦點設置在特定的選項卡上。
我該怎麼做?我能夠做到的唯一方法就是左鍵單擊它。
TabContent類:
class TabContent(wx.Panel) :
def __init__(self, parent, id) :
# Calls the constructor for wx.Panel
wx.Panel.__init__(self, parent = parent, id = id)
# Creates a vertical sizer
sizer = wx.BoxSizer(wx.VERTICAL)
# Creates an empty multi-line 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)
筆記本類:
class Notebook(wx.Notebook) :
def __init__(self, parent) :
wx.Notebook.__init__(self, parent, id = wx.ID_ANY, style = wx.BK_DEFAULT)
# Initialises tab number to 1
self.untitledCounter = 1
# Adds an empty tab
self.addTab()
# Sets up events
self.Bind(wx.EVT_RIGHT_DOWN, self.onMouseRightClicked)
def onMouseRightClicked(self, event) :
print("Left button was clicked on tab " + str(self.GetCurrentPage().GetId()))
怎麼樣?當我右鍵點擊它時,我想要關注它,但是我已經嘗試過了,它不起作用。 對我來說,唯一的「工作方法」是左鍵點擊一個標籤,然後它被選中,當然關注它。有沒有辦法通過點擊右鍵來完成它? 是否有一個函數,一旦我點擊鼠標,獲取光標座標下的對象,例如? – Michael
@Michael,所以你有一個wxNotebook與一些頁面。一次只能選擇一個頁面。 IIUC,你想要的是做一個右鍵點擊頁面標題,並使該頁面被選中。我對嗎?如果我在相同的頁面標題上點擊左鍵怎麼辦? – Igor
是的,你說得對。如果你做了左鍵單擊它被選中,但我希望用戶能夠右鍵單擊一個選項卡;這將打開一個彈出菜單,其中包含一些選項,例如「關閉」,「全部關閉」等。當然,我需要一些方法來識別我點擊的標籤。例如,在_medit_中,如果你右鍵點擊一個標籤,它不會被聚焦,但你可以關閉它。 – Michael