wxPython – SetDefault() function in wx.Button

In this article we are going to learn about SetDefault() function associated with the wx.Button class of wxPython. This sets the button to be the default item in its top-level window (e.g. the panel or the dialog box containing it).
As normal, pressing return causes the default button to be depressed when the return key is pressed.

Syntax: wx.Button.SetDefault(self)

Parameters: No parameters

Return Type: wx.Window

Code Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

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()

chevron_right


Output Window:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Hi there I am a student of CGC COE, Landran in CSE department and have a great interest in programming

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.