📜  wxPython - 禁用按钮

📅  最后修改于: 2022-05-13 01:55:06.622000             🧑  作者: Mango

wxPython - 禁用按钮

在本文中,我们将了解如何禁用框架中的按钮。有时,当我们不希望用户按下按钮时,我们可以禁用按钮并且按钮变得不可点击。
为了禁用按钮,我们可以使用与 wxPython 的 wx.Button 类关联的 Disable()函数。

代码示例:

import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.InitUI()
  
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.pnl = wx.Panel(self)
        bmp = wx.Bitmap('download.jpg')
          
        # CREATE BUTTON AT POINT (20, 20)
        self.st = wx.Button(self.pnl, id = 1, label ="Button", pos =(20, 20),
                                size =(100, 30),  name ="button")
        # SET BUTTON DISABLED
        self.st.Disable()
        self.SetSize((350, 250))
        self.SetTitle('wx.Button')
        self.Centre()
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

输出图像: