Since this is something that I've wanted to know how to do for some time, I
sat down and figured out how to do programmatic screen captures for frames
in wxPython. I have no idea if this is a generally applicable approach, but
oh well, I think it's kind of cool...
Enjoy yourselves,
Mike
from wxPython.wx import *
class TestFrame(wxFrame):
def __init__( self ):
wxFrame.__init__( self, NULL, -1, "test")
sizer = wxBoxSizer( wxVERTICAL )
self.text = wxTextCtrl( self, -1, "testing" )
sizer.Add( self.text, 1, wxEXPAND )
ID = wxNewId()
sizer.Add( wxButton( self, ID, "ToFile"), 0, wxEXPAND )
EVT_BUTTON( self, ID, self.OnToFile )
self.SetAutoLayout(true)
self.SetSizer( sizer )
self.Layout()
def OnToFile( self, event ):
context = wxPaintDC( self )
memory = wxMemoryDC( )
x,y = self.GetClientSizeTuple()
bitmap = wxEmptyBitmap( x,y, -1 )
memory.SelectObject( bitmap )
memory.Blit( 0,0,x,y, context, 0,0)
memory.SelectObject( wxNullBitmap)
bitmap.SaveFile( "test.bmp", wxBITMAP_TYPE_BMP )
if __name__ == "__main__":
class App( wxPySimpleApp):
def OnInit( self ):
TestFrame().Show( 1)
return 1
App().MainLoop()