I am using python v2.7 and wxPython v3.0 on Windows 7 OS. In my application I have a panel named as myPanel
. I have a image as a background on myPanel
the image names is green.bmp
The myPanel
contains a button named as myButton
. This myButton
also contains an image as a background named as blue.bmp
Problem: I don't see myButton
on myPanel
when I execute my code. I can't figure it out why is it not working. Any help will be appreciated. If I don't use an image as an background for myPanel
then the myButton
is visible!
Code: The images can be downloaded from here Green.bmp and Blue.bmp. The code snippet is provided below:
import wx
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, size=(500,400))
myPanel = wx.Panel(self, -1, size=(300,200))
image_file1 = 'green.bmp'
image1 = wx.Image(image_file1, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
#---- Comment out the line below then the button is visible
self.bitmap2 = wx.StaticBitmap(myPanel, -1, image1, (0, 0))
myButton = wx.Button(myPanel, -1, size =(30,30), pos=(20,20))
image_file2 = 'blue.bmp'
image2 = wx.Image(image_file2, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap1 = wx.StaticBitmap(myButton, -1, image2, (0, 0))
if __name__=='__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="Test")
frame.Show()
app.MainLoop()
Thank you for your time!
I believe it is a parenting issue. You need to set the button's parent to be self.bitmap2, not myPanel. Otherwise, the two widgets will "stack" on top of each other.
See the following tutorial:
You can also diagnose this sort of thing by using the Widget Inspection Tool
I am using python v2.7 and wxPython v3.0 on Windows 7 OS. In my application I have a panel named as myPanel
. I have a image as a background on myPanel
the image names is green.bmp
The myPanel
contains a button named as myButton
. This myButton
also contains an image as a background named as blue.bmp
Problem: I don't see myButton
on myPanel
when I execute my code. I can't figure it out why is it not working. Any help will be appreciated. If I don't use an image as an background for myPanel
then the myButton
is visible!
Code: The images can be downloaded from here Green.bmp and Blue.bmp. The code snippet is provided below:
import wx
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, size=(500,400))
myPanel = wx.Panel(self, -1, size=(300,200))
image_file1 = 'green.bmp'
image1 = wx.Image(image_file1, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
#---- Comment out the line below then the button is visible
self.bitmap2 = wx.StaticBitmap(myPanel, -1, image1, (0, 0))
myButton = wx.Button(myPanel, -1, size =(30,30), pos=(20,20))
image_file2 = 'blue.bmp'
image2 = wx.Image(image_file2, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap1 = wx.StaticBitmap(myButton, -1, image2, (0, 0))
if __name__=='__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="Test")
frame.Show()
app.MainLoop()
Thank you for your time!
I believe it is a parenting issue. You need to set the button's parent to be self.bitmap2, not myPanel. Otherwise, the two widgets will "stack" on top of each other.
See the following tutorial:
You can also diagnose this sort of thing by using the Widget Inspection Tool
0 commentaires:
Enregistrer un commentaire