[wxPython-users] saving wx output as jpg

Peter Damoc pdamoc at gmail.com
Fri Dec 1 03:34:06 PST 2006


Here is a small sample that does just that... adapt it to your case. All the
relevant code is in OnButton. ;)

import wx

class SFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title=3D"Window Shot")
        self.SetBackgroundColour("magenta")
        ssbutton =3D wx.Button(self, label =3D "Press For Window Shot")
        box =3D wx.BoxSizer(wx.VERTICAL)
        box.Add(wx.StaticText(self, label=3D"Some Text"), 0, wx.ALIGN_CENTE=
R)
        box.Add(ssbutton, 0, wx.ALIGN_CENTER)
        self.SetSizer(box)

        ssbutton.Bind(wx.EVT_BUTTON, self.OnButton)

    def OnButton(self, evt):
        w, h =3D self.GetClientSize()
        dc =3D wx.ClientDC(self)
        mdc =3D wx.MemoryDC()
        img =3D wx.EmptyBitmap(w, h)
        mdc.SelectObject(img)
        mdc.Blit(0,0,w,h,dc,0,0)
        img.SaveFile("winshot.jpg", wx.BITMAP_TYPE_JPEG)
        evt.Skip()
        wx.Bell()

app =3D wx.App(0)
frame =3D SFrame()
frame.Show()
app.MainLoop()

On 12/1/06, Ketan C Maheshwari <kmaheshw at science.uva.nl> wrote:
>
> hi *:
>     how can i save the output of a wxprogram say a simple geometrical
> object in a frame, in the form of an image file? from within the program?
>
> thanks
> k
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>


-- =

There is NO FATE, we are the creators.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200612=
01/bc7d6423/attachment.htm


More information about the wxpython-users mailing list