在本文中,我們將學習與wxPython的wx.Button類關聯的SetDefault()函數。這會將按鈕設置為其頂層窗口(例如,包含該按鈕的麵板或對話框)中的默認項。
通常,按回車鍵會在按下回車鍵時按下默認按鈕。
用法: wx.Button.SetDefault(self)
參數:沒有參數
返回類型:窗口
代碼示例:
import wx
class MyDialog(wx.Dialog):
def __init__(self, parent, title):
super(MyDialog, self).__init__(parent, title = title, size =(250, 175))
panel = wx.Panel(self)
self.btn = wx.Button(panel, wx.ID_OK, label ="Default",
size =(50, 20), pos =(75, 50))
self.btn1 = wx.Button(panel, wx.ID_OK, label ="Not Default",
size =(90, 20), pos =(75, 100))
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title = title, size =(250, 150))
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
btn = wx.Button(panel, label ="Click", pos =(75, 10))
btn.Bind(wx.EVT_BUTTON, self.OnModal)
# SET BUTTON AS DEFAULT
btn.SetDefault()
self.SetMinSize((600, 400))
self.Centre()
self.Show(True)
def OnModal(self, event):
a = MyDialog(self, "Dialog").ShowModal()
ex = wx.App()
Mywin(None, 'Window')
ex.MainLoop()
輸出窗口:
相關用法
- Python dict setdefault()用法及代碼示例
- wxPython wx.StaticText SetLabel()用法及代碼示例
- wxPython wx.StaticText Create()用法及代碼示例
- wxPython wx.StaticText IsEllipsized()用法及代碼示例
- wxPython wx.Button SetLabel()用法及代碼示例
- wxPython wx.BitmapButton GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.StaticText SetBackgroundColour()用法及代碼示例
- wxPython wx.StaticText SetForegroundColour()用法及代碼示例
- wxPython wx.RadioBox GetItemLabel()用法及代碼示例
- wxPython wx.Button SetBitmapPosition()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – SetDefault() function in wx.Button。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。