Python Forum
[WxPython] wx.StaticBitmap change image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] wx.StaticBitmap change image
#5
(Jul-02-2018, 05:49 AM)Barrowman Wrote: Okay. So as I am learning I need some explanations as to how this works. I could not see how to fit these into a working program. I still can't figure out how to use it.
Also the combobox part you posted originally is not the same as the one in your reply.
At least I can see how it would change things if I could understand how a value of 0 for selection would be how to trigger a change in the image. What would happen if it was some other value?
hi, hi:
for example,you have n images.
image1.png
image2.png
Be careful, it has to be of the same resolution.

in the code below it has no image, so pay attention in
def change_image( self, event ):


program.py
import wx
import wx.xrc

wx.ID_CHANGE = 1000

###########################################################################
## Class MyFrame1
###########################################################################

class MyFrame1 ( wx.Frame ):
	
	def __init__( self, parent ):
		wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
		
		self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
		
		bSizer2 = wx.BoxSizer( wx.VERTICAL )
		
		self.image = wx.BitmapButton( self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
		bSizer2.Add( self.image, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
		
		self.buton = wx.Button( self, wx.ID_CHANGE, u"Change", wx.DefaultPosition, wx.Size( 80,60 ), 0 )
		bSizer2.Add( self.buton, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
		
		
		self.SetSizer( bSizer2 )
		self.Layout()
		
		self.Centre( wx.BOTH )
		
		# Connect Events
		self.buton.Bind( wx.EVT_BUTTON, self.change_image )
	
	def __del__( self ):
		pass
	
	
	# Virtual event handlers, overide them in your derived class
	def change_image( self, event ):
		event.Skip()  #change code for: a)
a)
self.image.SetBitmap(wx.Bitmap('image1.jpg'))
I used selection== 1 , because I work with combobox and this offers a list for example.
in combobox the selection starts from 0 to n, n is the limit that you have given to the list, so my code works like this:
selection = 0
selection = 1
selection = 2

you just need to add the
if __main__== '__init__':
     #code execute class MyFrame1
Reply


Messages In This Thread
wx.StaticBitmap change image - by royer14 - Jul-01-2018, 05:37 PM
RE: wx.StaticBitmap change image - by Barrowman - Jul-01-2018, 09:57 PM
RE: wx.StaticBitmap change image - by royer14 - Jul-01-2018, 11:27 PM
RE: wx.StaticBitmap change image - by Barrowman - Jul-02-2018, 05:49 AM
RE: wx.StaticBitmap change image - by royer14 - Jul-02-2018, 02:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter don't change the image DQT 2 1,670 Jul-22-2022, 10:26 AM
Last Post: menator01
  [Tkinter] How do I change an image dynamically LeeMadeux 7 32,256 Jun-04-2020, 10:00 PM
Last Post: deanhystad
  [WxPython] StaticBitmap: unexpected behaviour giu88 0 2,089 Oct-06-2018, 10:09 AM
Last Post: giu88

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020