1000个圆点与PaintDC的使用,OnSize时重画很棒

import wx
import random

class View(wx.Panel):
    def __init__(self, parent):
        super(View, self).__init__(parent)
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)
    def on_size(self, event): # OnSize时重画很棒,但无法应付部分覆盖
        event.Skip() # 好像这句话也没起作用
        self.Refresh()
    def on_paint(self, event):
        dc = wx.AutoBufferedPaintDC(self)
        dc.SetPen(wx.Pen('RED'))

        for i in range(100):
            w, h = self.GetSize()
            x = random.randint(1, w-1)
            y = random.randint(1, h-1)
            dc.DrawCircle(x, y, 5)
        # self.Refresh() # 如果加上这句,相当于自己调用自己,无线更新 class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None)
        self.SetTitle('My Title')
        self.SetClientSize((500, 500))
        self.Center()
        self.view = View(self)

def main():
    app = wx.App(False)
    frame = Frame()
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()

 

你可能感兴趣的:(paint)