当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


wxPython wx.Button SetDefault()用法及代码示例


在本文中,我们将学习与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()

输出窗口:




相关用法


注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython – SetDefault() function in wx.Button。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。