📌  相关文章
📜  wxPython – wx.Button 中的 GetAuthNeeded()函数

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

wxPython – wx.Button 中的 GetAuthNeeded()函数

在本文中,我们将学习与 wxPython 的 wx.Button 类关联的 GetAuthNeeded()函数。如果按钮上显示需要身份验证的符号,则 GetAuthNeeded()函数用于返回 True。
它不需要任何论据。

代码示例:

import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
  
        self.InitUI()
  
    def InitUI(self):
        self.pnl = wx.Panel(self)
        self.btn = wx.Button(self.pnl, label ='Button', pos =(20, 20))
        self.btn.SetAuthNeeded(True)
  
        # PRINT IF AUTHENTICATION IS NEEDED OR NOT USING GetAuthNeeded()
        if(self.btn.GetAuthNeeded()== True):
            print("Authentication is needed.")
        else:
            print("No Authentication is needed.")
        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()

控制台输出:

Authentication is needed.

输出窗口: