How to create a button (Phoenix)

Keywords : Button.


Introduction :

wx.Button is a simple widget.

It contains a text string.

It is used to trigger an action.

wx.Button styles :

wx.Button methods

SetDefault()

set the button to be the default item on a window

wx.Size GetDefaultSize()

get the default button size on a platform

(info by Jan Bodnar / Zetcode).


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Sample one

img_sample_one.png

   1 # sample_one.py
   2 
   3 """
   4 
   5 Author : Jan Bodnar
   6 Website : zetcode.com
   7 
   8 """
   9 
  10 import wx
  11 import random
  12 
  13 APP_SIZE_X = 300
  14 APP_SIZE_Y = 200
  15 
  16 # class MyButtons
  17 
  18 #---------------------------------------------------------------------------
  19 
  20 class MyButtons(wx.Dialog):
  21     def __init__(self, parent, id, title):
  22         wx.Dialog.__init__(self, parent, id, title,
  23                            size=(APP_SIZE_X, APP_SIZE_Y))
  24 
  25         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  26 
  27         #------------
  28 
  29         wx.Button(self, 1, '&Close', (50, 130))
  30         wx.Button(self, 2, '&Random Move', (150, 130), (110, -1))
  31 
  32         #------------
  33 
  34         self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
  35         self.Bind(wx.EVT_BUTTON, self.OnRandomMove, id=2)
  36 
  37         #------------
  38 
  39         self.Centre()
  40 
  41         #------------
  42 
  43         self.ShowModal()
  44         self.Destroy()
  45 
  46     #-----------------------------------------------------------------------
  47 
  48     def OnClose(self, event):
  49         self.Close(True)
  50 
  51 
  52     def OnRandomMove(self, event):
  53         screensize = wx.GetDisplaySize()
  54         randx = random.randrange(0, screensize.x - APP_SIZE_X)
  55         randy = random.randrange(0, screensize.y - APP_SIZE_Y)
  56         self.Move((randx, randy))
  57 
  58 #---------------------------------------------------------------------------
  59 
  60 app = wx.App(0)
  61 MyButtons(None, -1, 'wx.Button')
  62 app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Jan Bodnar (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

15/12/20 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a button (Phoenix) (last edited 2020-12-30 17:48:16 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.