import random
import wx

class MainFrame( wx.Frame ):
    def __init__( self ):
	wx.Frame.__init__( self, None, wx.ID_ANY )
	# arbitrary; problem occurs at any size
	maxx = 800
	maxy = 600
	self.SetSize( ( maxx, maxy ) )
	# the points of randomness
	x1 = random.random()
	y1 = random.random()
	x2 = random.random()
	y2 = random.random()

	# Draw the figures. Please don't berate me on style, this script is
	# for illustrative purposes only.
	self._Buffer = wx.EmptyBitmap( maxx, maxy )
	mdc = wx.MemoryDC()
	mdc.SelectObject( self._Buffer )
	gc = wx.GraphicsContext.Create( mdc )

	gc.SetBrush( wx.Brush( "white" ) )
	gc.DrawRectangle( 0, 0, maxx, maxy ) # background

	gc.SetPen( wx.Pen( "red" ) )
	gc.StrokeLine( x1*maxx, y1*maxy, x2*maxx, y2*maxy )

	gc.SetBrush( wx.Brush( "black" ) )
	gc.DrawEllipse( x1*maxx, y1*maxy, 20, 20 )
	gc.DrawEllipse( x2*maxx, y2*maxy, 20, 20 )

	#  create binding
	self.Bind( wx.EVT_PAINT, self.OnPaint )

    def OnPaint( self, evt ):
	wx.BufferedPaintDC( self, self._Buffer )

if __name__ == '__main__':
    app = wx.App( False )
    frame = MainFrame()
    frame.Show()
    app.MainLoop()