[Tutor] [wxPython-users] Dynamically loading images on the panel of GUI

Varsha Purohit varsha.purohit at gmail.com
Mon Dec 3 01:29:07 CET 2007


hello everyone,
        i made a small applicatin where i need to display an image on a
panel. and then when i press the read button it should read another image
and display it on the same panel. Its working but i have to press the read
button two times then only its working....

import wx
import os

APP_SIZE_X = 700
APP_SIZE_Y = 300


class MainWindow(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"Agent-Based Model of Residential
Development", size = (APP_SIZE_X, APP_SIZE_Y))

        self.panel = wx.Panel(self,-1)
        self.imageFile = "r10001t0.asc.jpg"  # provide a diff file name in
same directory/path
        self.bmp = wx.Image(self.imageFile,wx.BITMAP_TYPE_JPEG
).ConvertToBitmap()
        wx.StaticBitmap(self.panel, -1, self.bmp, (20,20), (80,120))

        button42 = wx.Button(self.panel, -1, "Read", pos=(240,20))
        self.Bind(wx.EVT_BUTTON, self.OnRead,button42)

    def OnRead(self,event):
        self.imageFile1="DSCN3378.jpg" # you have to provide a diff image
file name
        self.bmp = wx.Image(self.imageFile1,wx.BITMAP_TYPE_JPEG
).ConvertToBitmap()
        wx.StaticBitmap(self.panel, -1, self.bmp, (20,20), (80,120))


app = wx.PySimpleApp()
MainWindow().Show()
app.MainLoop()

Load two different jpeg images.
-- 
Varsha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071202/68045017/attachment-0001.htm 


More information about the Tutor mailing list