wxPython - 禁用按钮
在本文中,我们将了解如何禁用框架中的按钮。有时,当我们不希望用户按下按钮时,我们可以禁用按钮并且按钮变得不可点击。
为了禁用按钮,我们可以使用与 wxPython 的 wx.Button 类关联的 Disable()函数。
Syntax: wx.Button.Disable(Self)
Parameters: No parameters required in Disable() function.
代码示例:
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()
输出图像: