[wxPython-users] Binding button even with another class

Robin Dunn robin at alldunn.com
Fri Feb 8 14:12:18 PST 2008


Varsha Purohit wrote:
> Hello All,
>         I have a simple application where there is a frame which has one 
> image and a zoomin button. when i am clicking on the zoomin button it 
> should call another class which will display another version of the 
> image saved in local copy which is zoomed. But i am not getting any 
> error but even the new image is not being displayed. can you please 
> check and tell me wher ei am doing mistake. Actually when i click zoomin 
> another window should come on top of the frame which will have 
> scrollbars and show the new zoomed image.
> 
> this is my code : -
> import wx
> 
> class ScrolledWindow(wx.Panel):
>     def __init__(self, parent, id=-1):
>         wx.Panel.__init__(self, parent, id=-1)
> 
>         #Display the zoomed version of the image in the panel.
>         sw = wx.ScrolledWindow(self)

You are creating a new scrolled window as a child of self.  Why?  You 
could just make this class derive from wx.ScrolledWindow instead, and 
put the bitmap here and do the scrolling with self.


>         bmp = wx.Image('Nearest.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
>         wx.StaticBitmap(sw, -1, bmp, (120,250), (580,400))
>         sw.SetScrollbars(20, 20, 55, 40)
>         #sw.Scroll(50,10)
>         self.Centre()
>         self.Show()

No need to Show this.  It's not a top level window and so it starts out 
shown by default.

> 
> class MyFrame(wx.Frame):
>     def __init__(self, parent, id):
>         # create a panel
>         wx.Frame.__init__(self, parent, id=-1, size = (820, 710))
>         self.SetBackgroundColour("white")
> 
>         self.bmp = wx.Image('srk.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
>         wx.StaticBitmap(self, -1, self.bmp, (120,250), (580,400))
> 
> 
>         self.button11 = wx.Button(self, -1, "Zoom in", (30,240))
>         self.button11.Bind(wx.EVT_BUTTON, self.resizeImage)
>         self.Centre()
>         self.Show()
> 
>     def resizeImage(self, event):
>         panel = ScrolledWindow(self)

What if there is already another panel?  You should either destroy it, 
or reuse it.  Also if you want this panel to fill the frame then you'll 
need to tell it to do so one way or another because the frame will 
already have been sized so the default behavior that happens in the 
frame's EVT_SIZE handler will not have any effect until the frame's size 
changes again.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list