Is it possible to bind an on click event to wx.StaticText?

I have this code:

import wx class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): panel = wx.Panel.__init__(self, parent, *args, **kwargs) self.colorOver = ((89,89,89)) self.colorLeave = ((110,110,110)) self.colorFont = ((131,131,131)) self.SetBackgroundColour(self.colorLeave) self.SetForegroundColour(self.colorLeave) self.name = "Plugin" self.overPanel = 0 self.overLabel = 0 sizer = wx.BoxSizer(wx.VERTICAL) name = wx.StaticText(self, -1, ' ' + self.getName()) close = wx.StaticText(self, -1, ' X ') gs = wx.GridSizer(2, 2, 0, 0) gs.AddMany([(name, 0, wx.ALIGN_LEFT), (close, 0, wx.ALIGN_RIGHT)]) sizer.Add(gs, 1, wx.EXPAND) self.SetSizer(sizer) .... .... 

Can I left-click on closing StaticText and hide the panel?

+4
source share
2 answers

I don't know if wx.EVT_LEFT_DOWN can be bound to a StaticText widget. You can use the button to call self.Hide (). Perhaps BitmapButton if you want a custom look.

 class myPanel(wx.Panel): def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) bitmap = wx.EmptyBitmap(15,15) self.button = wx.BitmapButton(self, -1, bitmap=bitmap, size=(15,15), style=wx.NO_BORDER) self.Bind(wx.EVT_BUTTON, self.onClick, self.button) def onClick(self, event): self.Hide() 
+4
source

It seems to me that I have to put static text inside a frame or some object that could receive events, but was made invisible. Then the click event in the text is passed to the parent element. I used to have a special derived class for interactive tags.

+3
source

Source: https://habr.com/ru/post/1301917/


All Articles