I need help with GenBitmapTextButton

Marcelo Barbero marcelobarbero at arnet.com.ar
Mon Oct 9 16:25:52 PDT 2006


I need to put the number in the code below INTO the picture (picture not
included, choose a little squared Windows bitmap, for example: 100x100).

How can I do that?

Python 2.4.3, wxPython 2.6.3, Windows XP.

Thanks in advance.

Marcelo


#-- Here is the code --
import wx
import wx.lib.buttons as buttons

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Test")
        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour("black")

        # I will need a gridsizer later
        self.grilla = wx.GridSizer(cols=2, hgap=0, vgap=0)

	  # CHANGE THE BITMAP FILE NAME!!!
        bmp = wx.Image("change_here.bmp",
                       wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        number = "42"
        b = buttons.GenBitmapTextButton(self.panel, -1, bmp, label=number,
                                        style=wx.NO_BORDER)
        b.SetFont(wx.Font(30, wx.SWISS, wx.NORMAL, wx.BOLD, False))
        b.SetBackgroundColour("black")
        b.SetForegroundColour("gray")
        b.SetToolTipString(number)

        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
        self.grilla.Add(b, 0, wx.EXPAND)

        self.panel.SetSizer(self.grilla)

    def OnClick(self, event):
        pressed_button = event.GetEventObject()
        if pressed_button.GetForegroundColour() == "gray":
            pressed_button.SetForegroundColour("white")
        else:
            pressed_button.SetForegroundColour("gray")


app = wx.App()
frame = MyFrame()
frame.Show(True)
app.MainLoop()

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.407 / Virus Database: 268.13.1/466 - Release Date: 07/10/2006
 





More information about the wxpython-users mailing list