當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.Button SetLabel()用法及代碼示例

在本文中,我們將學習與wxPython的wx.Button類關聯的SetLabel()函數。 SetLabel()函數用於設置按鈕的字符串標簽。

它帶有一個用作按鈕標簽的字符串參數。

用法: wx.Button.SetLabel(self, label)

參數:

參數 輸入類型 描述
label string 要設置的標簽。

代碼示例:

import wx 
  
class Mywin(wx.Frame):
  
    def __init__(self, parent, title):
        super(Mywin, self).__init__(parent, title = title, size =(250, 150)) 
        self.InitUI() 
  
    def InitUI(self):
        self.panel = wx.Panel(self) 
        self.btn = wx.Button(self.panel, label ="Click", pos =(75, 10)) 
        self.btn.Bind(wx.EVT_BUTTON, self.Onclick) 
  
        self.SetMinSize((400, 250)) 
        self.Centre() 
        self.Show(True) 
  
    def Onclick(self, event):
        # SET A STRING LABEL FOR BUTTON 
        self.btn.SetLabel("Clicked") 
  
  
ex = wx.App() 
Mywin(None, 'Window') 
ex.MainLoop()

輸出窗口:

在點擊按鈕之前


單擊按鈕後

相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – SetLabel() function in wx.Button。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。