User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,515 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,713 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 782 | Replies: 7
Reply
Join Date: Sep 2007
Posts: 12
Reputation: ndoe is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ndoe ndoe is offline Offline
Newbie Poster

Help showing image by click button

  #1  
Sep 26th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Posts: 2,529
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: showing image by click button

  #2  
Sep 27th, 2007
We need to see some code so we figure out which GUI toolkit you are using and which picture format you want to load.
May 'the Google' be with you!
Reply With Quote  
Join Date: Sep 2007
Posts: 12
Reputation: ndoe is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ndoe ndoe is offline Offline
Newbie Poster

Re: showing image by click button

  #3  
Sep 27th, 2007
Originally Posted by vegaseat View Post
We need to see some code so we figure out which GUI toolkit you are using and which picture format you want to load.

[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
Last edited by ndoe : Sep 27th, 2007 at 10:50 pm.
Reply With Quote  
Join Date: Aug 2007
Location: New Hampshire
Posts: 3,417
Reputation: jasimp will become famous soon enough jasimp will become famous soon enough 
Rep Power: 9
Solved Threads: 31
jasimp's Avatar
jasimp jasimp is offline Offline
Nearly a Senior Poster

Re: showing image by click button

  #4  
Sep 28th, 2007
You need to close your tag with [/code] not [/python]
  1.  
  2. import wx
  3. def create(parent):
  4. return Frame1(parent)
  5.  
  6. [wxID_FRAME1, wxID_FRAME1BITMAPBUTTON1, wxID_FRAME1BITMAPBUTTON2,
  7. wxID_FRAME1PANEL1, wxID_FRAME1PANEL2,
  8. ] = [wx.NewId() for _init_ctrls in range(5)]
  9.  
  10. class Frame1(wx.Frame):
  11. def _init_ctrls(self, prnt):
  12. # generated method, don't edit
  13. wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  14. pos=wx.Point(353, 258), size=wx.Size(773, 542),
  15. style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  16. self.SetClientSize(wx.Size(765, 515))
  17.  
  18. self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
  19. pos=wx.Point(40, 24), size=wx.Size(96, 104),
  20. style=wx.TAB_TRAVERSAL)
  21.  
  22. self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2', parent=self,
  23. pos=wx.Point(216, 80), size=wx.Size(408, 200),
  24. style=wx.SIMPLE_BORDER)
  25.  
  26.  
  27. self.bitmapButton1 = wx.BitmapButton(bitmap= wx.Bitmap(u'tai.bmp',wx.BITMAP_TYPE_BMP),
  28. id=wxID_FRAME1BITMAPBUTTON1, name='bitmapButton1',
  29. parent=self.panel1, pos=wx.Point(16, 8), size=wx.Size(48, 24),
  30. style=wx.BU_AUTODRAW)
  31. self.bitmapButton1.Bind(wx.EVT_BUTTON, self.OnBitmapButton1Button,
  32. id=wxID_FRAME1BITMAPBUTTON1)
  33.  
  34. self.bitmapButton2 = wx.BitmapButton(bitmap= wx.Bitmap(u'bau.bmp',wx.BITMAP_TYPE_BMP),
  35. id=wxID_FRAME1BITMAPBUTTON2, name='bitmapButton2',
  36. parent=self.panel1, pos=wx.Point(16, 56), size=wx.Size(48, 24),
  37. style=wx.BU_AUTODRAW)
  38. self.bitmapButton2.Bind(wx.EVT_BUTTON, self.OnBitmapButton2Button,
  39. id=wxID_FRAME1BITMAPBUTTON2)
  40.  
  41. self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
  42. self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
  43. self.Bind(wx.EVT_MOTION, self.OnMotion)
  44. self.Bind(wx.EVT_PAINT, self.OnPaint)
  45. self.pos = wx.Point(0,0)
  46.  
  47.  
  48. def __init__(self, parent):
  49. self._init_ctrls(parent)
  50.  
  51.  
  52. def OnBitmapButton1Button(self,event):
  53. pass
  54.  
  55. def OnBitmapButton2Button(self,event):
  56. pass
  57.  
  58. def OnLeftDown(self, event):
  59. pass
  60.  
  61. def OnLeftUp(self, event):
  62. pass
  63.  
  64. def OnMotion(self, event):
  65. pass
  66.  
  67. def OnPaint(self, event):
  68. pass
Last edited by jasimp : Sep 28th, 2007 at 3:53 pm.
A room without books is like a body without a soul.
Facts are meaningless. They can be used to prove anything that is even remotely true.
Go then, there are other worlds than these.
Reply With Quote  
Join Date: Oct 2004
Posts: 2,529
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: showing image by click button

  #5  
Sep 28th, 2007
Here would be a typical example of a wx.BitmapButton ...
  1. # Templet of a wxPython Frame, Panel and BitmapButton
  2.  
  3. import wx
  4.  
  5. class MyFrame(wx.Frame):
  6. """make a frame, inherits wx.Frame"""
  7. def __init__(self):
  8. # create a frame/window, no parent, default to wxID_ANY
  9. wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton',
  10. pos=(300, 150), size=(300, 350))
  11. # panel needed to display button correctly
  12. self.panel1 = wx.Panel(self, -1)
  13.  
  14. # pick a button image file you have (.bmp .jpg .gif or .png)
  15. imageFile = "Btn_down.jpg"
  16. image1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
  17. self.button1 = wx.BitmapButton(self.panel1, id=-1, bitmap=image1,
  18. pos=(10, 20), size = (image1.GetWidth()+5, image1.GetHeight()+5))
  19. self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
  20.  
  21. # show the frame
  22. self.Show(True)
  23.  
  24. def button1Click(self,event):
  25. self.SetTitle("Button1 clicked") # test
  26.  
  27. application = wx.PySimpleApp()
  28. # call class MyFrame
  29. window = MyFrame()
  30. # start the event loop
  31. application.MainLoop()
Attached Images
File Type: jpg Btn_down.JPG (1.7 KB, 17 views)
May 'the Google' be with you!
Reply With Quote  
Join Date: Oct 2004
Posts: 2,529
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: showing image by click button

  #6  
Sep 28th, 2007
This would be an example of wxPython when you want to click a button to show an image ...
  1. # show an image on a panel using wxPython
  2.  
  3. import wx
  4.  
  5. class MyFrame(wx.Frame):
  6. """create a frame with a button and a panel"""
  7. def __init__(self, parent, id):
  8. wx.Frame.__init__(self, parent, -1, title="Image", size=(500,400))
  9. self.btn = wx.Button(self, -1, "Show Image", pos=(10, 0), size=(90, 20))
  10. self.btn.Bind(wx.EVT_BUTTON, self.onClickButton)
  11. self.panel = wx.Panel(self, -1, pos=(0, 25), size=(500, 380))
  12.  
  13. def onClickButton(self, event):
  14. # pick a .bmp, .jpg, .gif. or .png file you have
  15. # (if not in the working folder add full path)
  16. image_file = 'AceSpade.bmp'
  17. bmp = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
  18. width = bmp.GetWidth()
  19. height = bmp.GetHeight()
  20. # show the bitmap, you need to set size, image's upper
  21. # left corner anchors at panel coordinates (5, 5)
  22. wx.StaticBitmap(self.panel, -1, bmp, pos=(5, 5), size=(width, height))
  23.  
  24.  
  25. app = wx.PySimpleApp()
  26. # create a window/frame, no parent, -1 is default ID
  27. frame = MyFrame(None, -1)
  28. frame.Show(True)
  29. app.MainLoop()
May 'the Google' be with you!
Reply With Quote  
Join Date: Sep 2007
Posts: 12
Reputation: ndoe is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ndoe ndoe is offline Offline
Newbie Poster

Re: showing image by click button

  #7  
Oct 2nd, 2007
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
Reply With Quote  
Join Date: Oct 2004
Posts: 2,529
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: showing image by click button

  #8  
Oct 2nd, 2007
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!
May 'the Google' be with you!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 3:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC