How to create a button (Phoenix)
Keywords : Button.
Contents
Introduction :
wx.Button is a simple widget.
It contains a text string.
It is used to trigger an action.
wx.Button styles :
- wx.BU_LEFT
- wx.BU_TOP
- wx.BU_RIGHT
- wx.BU_BOTTOM
- wx.BU_EXACTFIT
- wx.NO_BORDER
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
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
Additional Information
Link :
- - - - -
https://wiki.wxpython.org/TitleIndex
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....