1

I want to draw some lines after click button. But when I minimize the window, or scroll the window in a ScrolledWindow, all the drawing will lost. Is there any way to keep them?

Here is the code:

import wx

class Frame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, -1, size=(640, 480))
        self.panel = wx.Panel(self, wx.ID_ANY)

        button = wx.Button(self.panel, id=wx.ID_ANY, label=u'Start Calculation', size=(160, 22))
        self.Bind(wx.EVT_BUTTON, self.OnButtonCalcuating, button)


    def OnButtonCalcuating(self, event):
        self.dc = wx.ClientDC(self.panel)
        self.dc.DrawLine(50, 60, 190, 60)


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Frame()
    frame.Show()
    app.MainLoop()
HWW
  • 557
  • 2
  • 6
  • 15

1 Answers1

2

If you want to paint into your window, you must make a handler for EVT_PAINT event. What you do is, that you paint your line, but that's it. When the window gets re-drawn, and knows nothing about your line anymore.

Check out this: http://wiki.wxpython.org/VerySimpleDrawing

Petr Blahos
  • 2,253
  • 1
  • 11
  • 14