•
•
•
•
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
![]() |
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
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
it need some array ? or it just click and show? thanks for your help,i need it for my task
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Aug 2007
Location: New Hampshire
Posts: 3,417
Reputation:
Rep Power: 9
Solved Threads: 31
You need to close your tag with [/code] not [/python]
python Syntax (Toggle Plain Text)
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
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.
Facts are meaningless. They can be used to prove anything that is even remotely true.
Go then, there are other worlds than these.
Here would be a typical example of a wx.BitmapButton ...
python Syntax (Toggle Plain Text)
# 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()
May 'the Google' be with you!
This would be an example of wxPython when you want to click a button to show an image ...
python Syntax (Toggle Plain Text)
# 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()
May 'the Google' be with you!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Dual Booting Problem (Techies' Lounge)
- change input's bg image with js (JavaScript / DHTML / AJAX)
- how to get to next record on click of a button. (JavaScript / DHTML / AJAX)
- how to get to next record on click of a button (JSP)
- Photoshop: Aqua Button (Graphics and Multimedia)
- Passes variable when button is clicked...HELP! (ASP)
- how do i get the current time when i click a button? (ASP)
- problem:on click button pagr refresh again (VB.NET)
- error message when I click a button (ASP)
Other Threads in the Python Forum
- Previous Thread: wxpython TextCtrl Basic Formatting
- Next Thread: Python executing in bash env



Linear Mode