gpt4 book ai didi

python - 是否可以在 wx.StaticText 上绑定(bind)点击事件?

转载 作者:太空狗 更新时间:2023-10-30 02:23:43 27 4
gpt4 key购买 nike

我有这个代码:

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)

.... ....

是否可以左键单击 StaticText 关闭并隐藏面板本身?

最佳答案

我不知道是否可以将 wx.EVT_LEFT_DOWN 绑定(bind)到 StaticText 小部件。您可以使用按钮来调用 self.Hide()。如果您想要自定义外观,可以使用 BitmapButton。

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()

关于python - 是否可以在 wx.StaticText 上绑定(bind)点击事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2302886/

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