hello all,i hope you all can help for this,i want showing image by clicking button,i have 5 button with parents panel 1 and i want show image to panel 2,my plan the image can be drag or rezise and image show all the time user want,i have idea for drag and rezise but for showing i haven't.
it need some array ? or it just click and show? thanks for your help,i need it for my task

We need to see some code so we figure out which GUI toolkit you are using and which picture format you want to load.

We need to see some code so we figure out which GUI toolkit you are using and which picture format you want to load.

import wx def create(parent): return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BITMAPBUTTON1, wxID_FRAME1BITMAPBUTTON2, wxID_FRAME1PANEL1, wxID_FRAME1PANEL2, ] = [wx.NewId() for _init_ctrls in range(5)]

class Frame1(wx.Frame): def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(353, 258), size=wx.Size(773, 542), style=wx.DEFAULT_FRAME_STYLE, title='Frame1') self.SetClientSize(wx.Size(765, 515))

self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(40, 24), size=wx.Size(96, 104), style=wx.TAB_TRAVERSAL)

self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2', parent=self, pos=wx.Point(216, 80), size=wx.Size(408, 200), style=wx.SIMPLE_BORDER)

self.bitmapButton1 = wx.BitmapButton(bitmap= wx.Bitmap(u'tai.bmp',wx.BITMAP_TYPE_BMP), id=wxID_FRAME1BITMAPBUTTON1, name='bitmapButton1', parent=self.panel1, pos=wx.Point(16, 8), size=wx.Size(48, 24), style=wx.BU_AUTODRAW) self.bitmapButton1.Bind(wx.EVT_BUTTON, self.OnBitmapButton1Button, id=wxID_FRAME1BITMAPBUTTON1)

self.bitmapButton2 = wx.BitmapButton(bitmap= wx.Bitmap(u'bau.bmp',wx.BITMAP_TYPE_BMP), id=wxID_FRAME1BITMAPBUTTON2, name='bitmapButton2', parent=self.panel1, pos=wx.Point(16, 56), size=wx.Size(48, 24), style=wx.BU_AUTODRAW) self.bitmapButton2.Bind(wx.EVT_BUTTON, self.OnBitmapButton2Button, id=wxID_FRAME1BITMAPBUTTON2) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMotion) self.Bind(wx.EVT_PAINT, self.OnPaint) self.pos = wx.Point(0,0) def __init__(self, parent): self._init_ctrls(parent) def OnBitmapButton1Button(self,event): pass def OnBitmapButton2Button(self,event): pass def OnLeftDown(self, event): pass

def OnLeftUp(self, event): pass def OnMotion(self, event): pass def OnPaint(self, event): pass [/python] here thet are the source code i use boa,and i use picture *.bmp, i not write the source code on the button because i now it wrong,thanks for your helps[code=python]
import wx
def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BITMAPBUTTON1, wxID_FRAME1BITMAPBUTTON2,
wxID_FRAME1PANEL1, wxID_FRAME1PANEL2,
] = [wx.NewId() for _init_ctrls in range(5)]

class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(353, 258), size=wx.Size(773, 542),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(765, 515))

self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(40, 24), size=wx.Size(96, 104),
style=wx.TAB_TRAVERSAL)

self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2', parent=self,
pos=wx.Point(216, 80), size=wx.Size(408, 200),
style=wx.SIMPLE_BORDER)


self.bitmapButton1 = wx.BitmapButton(bitmap= wx.Bitmap(u'tai.bmp',wx.BITMAP_TYPE_BMP),
id=wxID_FRAME1BITMAPBUTTON1, name='bitmapButton1',
parent=self.panel1, pos=wx.Point(16, 8), size=wx.Size(48, 24),
style=wx.BU_AUTODRAW)
self.bitmapButton1.Bind(wx.EVT_BUTTON, self.OnBitmapButton1Button,
id=wxID_FRAME1BITMAPBUTTON1)

self.bitmapButton2 = wx.BitmapButton(bitmap= wx.Bitmap(u'bau.bmp',wx.BITMAP_TYPE_BMP),
id=wxID_FRAME1BITMAPBUTTON2, name='bitmapButton2',
parent=self.panel1, pos=wx.Point(16, 56), size=wx.Size(48, 24),
style=wx.BU_AUTODRAW)
self.bitmapButton2.Bind(wx.EVT_BUTTON, self.OnBitmapButton2Button,
id=wxID_FRAME1BITMAPBUTTON2)

self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.pos = wx.Point(0,0)


def __init__(self, parent):
self._init_ctrls(parent)


def OnBitmapButton1Button(self,event):
pass

def OnBitmapButton2Button(self,event):
pass

def OnLeftDown(self, event):
pass

def OnLeftUp(self, event):
pass

def OnMotion(self, event):
pass

def OnPaint(self, event):
pass
[/python]
here thet are the source code i use boa,and i use picture *.bmp, i not write the source code on the button because i now it wrong,thanks for your helps

You need to close your tag with
[/code] not [/python]

import wx
def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BITMAPBUTTON1, wxID_FRAME1BITMAPBUTTON2,
wxID_FRAME1PANEL1, wxID_FRAME1PANEL2,
] = [wx.NewId() for _init_ctrls in range(5)]

class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(353, 258), size=wx.Size(773, 542),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(765, 515))

self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(40, 24), size=wx.Size(96, 104),
style=wx.TAB_TRAVERSAL)

self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2', parent=self,
pos=wx.Point(216, 80), size=wx.Size(408, 200),
style=wx.SIMPLE_BORDER)


self.bitmapButton1 = wx.BitmapButton(bitmap= wx.Bitmap(u'tai.bmp',wx.BITMAP_TYPE_BMP),
id=wxID_FRAME1BITMAPBUTTON1, name='bitmapButton1',
parent=self.panel1, pos=wx.Point(16, 8), size=wx.Size(48, 24),
style=wx.BU_AUTODRAW)
self.bitmapButton1.Bind(wx.EVT_BUTTON, self.OnBitmapButton1Button,
id=wxID_FRAME1BITMAPBUTTON1)

self.bitmapButton2 = wx.BitmapButton(bitmap= wx.Bitmap(u'bau.bmp',wx.BITMAP_TYPE_BMP),
id=wxID_FRAME1BITMAPBUTTON2, name='bitmapButton2',
parent=self.panel1, pos=wx.Point(16, 56), size=wx.Size(48, 24),
style=wx.BU_AUTODRAW)
self.bitmapButton2.Bind(wx.EVT_BUTTON, self.OnBitmapButton2Button,
id=wxID_FRAME1BITMAPBUTTON2)

self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.pos = wx.Point(0,0)


def __init__(self, parent):
self._init_ctrls(parent)


def OnBitmapButton1Button(self,event):
pass

def OnBitmapButton2Button(self,event):
pass

def OnLeftDown(self, event):
pass

def OnLeftUp(self, event):
pass

def OnMotion(self, event):
pass

def OnPaint(self, event):
pass

Here would be a typical example of a wx.BitmapButton ...

# Templet of a wxPython Frame, Panel and BitmapButton
 
import wx
 
class MyFrame(wx.Frame):
    """make a frame, inherits wx.Frame"""
    def __init__(self):
        # create a frame/window, no parent, default to wxID_ANY
        wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton',
            pos=(300, 150), size=(300, 350))
        # panel needed to display button correctly
        self.panel1 = wx.Panel(self, -1)
        
        # pick a button image file you have (.bmp .jpg .gif or .png)
        imageFile = "Btn_down.jpg"
        image1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.button1 = wx.BitmapButton(self.panel1, id=-1, bitmap=image1,
            pos=(10, 20), size = (image1.GetWidth()+5, image1.GetHeight()+5))
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
        
        # show the frame
        self.Show(True)
 
    def button1Click(self,event):
        self.SetTitle("Button1 clicked")  # test
        
application = wx.PySimpleApp()
# call class MyFrame
window = MyFrame()
# start the event loop
application.MainLoop()
Attachments Btn_down.JPG 1.71 KB

This would be an example of wxPython when you want to click a button to show an image ...

# show an image on a panel using wxPython
 
import wx
 
class MyFrame(wx.Frame):
    """create a frame with a button and a panel"""
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, -1, title="Image", size=(500,400))
        self.btn = wx.Button(self, -1, "Show Image", pos=(10, 0), size=(90, 20))
        self.btn.Bind(wx.EVT_BUTTON, self.onClickButton)
        self.panel = wx.Panel(self, -1, pos=(0, 25), size=(500, 380))
 
    def onClickButton(self, event):
        # pick a .bmp, .jpg, .gif. or .png file you have
        # (if not in the working folder add full path)
        image_file = 'AceSpade.bmp'
        bmp = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        width = bmp.GetWidth()
        height = bmp.GetHeight()
        # show the bitmap, you need to set size, image's upper
        # left corner anchors at panel coordinates (5, 5)
        wx.StaticBitmap(self.panel, -1, bmp, pos=(5, 5), size=(width, height))
 

app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID 
frame = MyFrame(None, -1)
frame.Show(True)
app.MainLoop()

can we show the bitmap wihout library from wx.staticbitmap,i mean if i want show the image and
then i want drag or resize the image,can we use another library for show image,example wx.bitmap or wx.image,thank for your helps

There is an example for dragging an image in the wxPython demos. For resizing an image you best use the Python Image Library (PIL), save the result, and then load into wxPython.

I really need to put this on my list of Python things to play around with!

This question has already been answered. Start a new discussion instead.