wxPyhon – BitmapButton using Create() method

In this article we will learn about how we can create a BitmapButton using Create() function. Create() function is a button creation function for two-step creation. BitmapButton() constructor cannot be used for two step BitmapButton creation.
It takes different Bitmap Button attributes as parameters.
Syntax: wx.BitmapButton.Create(self, parent, id=ID_ANY, bitmap=NullBitmap, pos=DefaultPosition, size=DefaultSize, style=0, validator=DefaultValidator, name=ButtonNameStr)
Parameters:
Parameter Input Type Description parent wx.Window Parent window. Should not be None. id wx.WindowID Control identifier. A value of -1 denotes a default value. bitmap wx.Bitmap Bitto be displayed. pos wx.Point Window position. size wx.Window Window size. style long Window style. validator wx.Validator Window validator. name string Window name. Return Type:
bool
Code Example:
import wx class Mywin(wx.Frame): def __init__(self, parent, title): super(Mywin, self).__init__(parent, title = title, size =(250, 150)) self.InitUI() def InitUI(self): self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) self.panel = wx.Panel(self) self.btn = wx.BitmapButton() bmp = wx.Bitmap('right.png') # CREATE BITMAPBUTTON USING Create() function self.btn.Create(self.panel, id = wx.ID_ANY, bitmap = bmp, size =(bmp.GetWidth()+10, bmp.GetHeight()+10)) self.SetMinSize((400, 250)) self.Centre() self.Show(True) ex = wx.App() Mywin(None, 'Window') ex.MainLoop() |
Output Window:



