user2678904
user2678904

Reputation:

Bitmap button won´t be displayed

It´s maybe weird question but i haven´t found something like this, so i am asking. I want to display my Bitmap button, i have code and it is working pretty good, but it won´t display the button! If i write code to empty IDLE, it is working and showing the bitmap button, but in IDLE, where i have already imported some pictures it isn´t showing the button! And of course button has other coordinates than other images. Here is code:

    import wx

class GameFrame(wx.Frame):

def __init__(self,parent,id):

    wx.Frame.__init__(self, parent, id, "Project", style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX, size=(860, 640))
    wx.Frame.CenterOnScreen(self)

    panel = wx.Panel(self)
    self.SetBackgroundColour("green")

Here I am importing some pictures and then i import the bitmap button:

            smallsoundstudioimg = wx.Image("Images/SmallSoundStudio.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.sssbtn=wx.BitmapButton(panel, -1, smallsoundstudioimg, pos=(64,64))
    self.Bind(wx.EVT_BUTTON, self.sssaction, self.sssbtn)
    self.sssbtn.SetDefault()

def sssaction(self, event):
    print "Small Sound Studio"

    if __name__=='__main__':
    app=wx.App()
    frame=GameFrame(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

Please help somebody!
Thank you very much for all advices!

Upvotes: 0

Views: 95

Answers (2)

user2678904
user2678904

Reputation:

I have found out where is the problem. I have write code to other .py document and it shows just little square on the right top corner of frame. If coordinate are 0, 0 it shows really small part of button and when i click on it, it prints Clicked. Here is code:

import wx

class MyFrame(wx.Frame):
def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, 'Bitmap Button', pos=(300, 150), size=(300, 350))
    self.panel1 = wx.Panel(self, -1)

    imageFile = "SmallSoundStudio.png"
    image1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.button1 = wx.BitmapButton(self.panel1, id=-1, bitmap=image1, pos=(10, 10))
    self.button1.Bind(wx.EVT_BUTTON, self.button1Click)

    roadimg = wx.Bitmap("SmallSoundStudio.png")
    cntrlrdimg = wx.StaticBitmap(self, -1, roadimg)
    cntrlrdimg.SetPosition((250, 250))

    self.Show(True)

def button1Click(self,event):
    print "Clicked"

application = wx.App()
window = MyFrame()
application.MainLoop()

Upvotes: 0

Mike Driscoll
Mike Driscoll

Reputation: 33071

Your code works for me. I edited it slightly to use wx.ArtProvider as you didn't provide the image you were using. Here is my version:

import wx

class GameFrame(wx.Frame):
    def __init__(self,parent,id):

        wx.Frame.__init__(self, parent, id, "Project", style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX, size=(860, 640))
        wx.Frame.CenterOnScreen(self)

        panel = wx.Panel(self)
        self.SetBackgroundColour("green")

        smallsoundstudioimg = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, (36,36))

        self.sssbtn=wx.BitmapButton(panel, -1, smallsoundstudioimg, pos=(64,64))
        self.Bind(wx.EVT_BUTTON, self.sssaction, self.sssbtn)
        self.sssbtn.SetDefault()

    def sssaction(self, event):
        print "Small Sound Studio"

if __name__=='__main__':
    app=wx.App()
    frame=GameFrame(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

Upvotes: 1

Related Questions