圆月山庄资源网 Design By www.vgjia.com

本文实例为大家分享了wxPython绘图小例子的具体实现代码,供大家参考,具体内容如下

一个绘图的例子:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
'''
  Function:绘图
  Input:NONE
  Output: NONE
  author: socrates
  blog:http://www.cnblogs.com/dyx1024/
  date:2012-07-11
''' 
 
import wx
 
class PaintWindow(wx.Window):
    def __init__(self, parent, id):
      wx.Window.__init__(self, parent, id)
      self.SetBackgroundColour("Red")
      self.color = "Green"
      self.thickness = 10
    
      #创建一个画笔
      self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
      self.lines = []
      self.curLine = []
      self.pos = (0, 0)
      self.InitBuffer()
    
      #连接事件
      self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
      self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
      self.Bind(wx.EVT_MOTION, self.OnMotion)
      self.Bind(wx.EVT_SIZE, self.OnSize)
      self.Bind(wx.EVT_IDLE, self.OnIdle)
      self.Bind(wx.EVT_PAINT, self.OnPaint)
    
    def InitBuffer(self):
      size = self.GetClientSize()
      
      #创建缓存的设备上下文
      self.buffer = wx.EmptyBitmap(size.width, size.height)
      dc = wx.BufferedDC(None, self.buffer)
      
      #使用设备上下文
      dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
      dc.Clear()
      self.DrawLines(dc)
      self.reInitBuffer = False
      
    def GetLinesData(self):
      return self.lines[:]
    
    def SetLinesData(self, lines):
      self.lines = lines[:]
      self.InitBuffer()
      self.Refresh()
      
    def OnLeftDown(self, event):
      self.curLine = []
      
      #获取鼠标位置
      self.pos = event.GetPositionTuple()
      self.CaptureMouse()
      
    def OnLeftUp(self, event):
      if self.HasCapture():
        self.lines.append((self.color,
                  self.thickness,
                  self.curLine))
        self.curLine = []
        self.ReleaseMouse()
        
    def OnMotion(self, event):
      if event.Dragging() and event.LeftIsDown():
        dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
        self.drawMotion(dc, event)
      event.Skip()
    
    def drawMotion(self, dc, event):
      dc.SetPen(self.pen)
      newPos = event.GetPositionTuple()
      coords = self.pos + newPos
      self.curLine.append(coords)
      dc.DrawLine(*coords)
      self.pos = newPos
      
    def OnSize(self, event):
      self.reInitBuffer = True
    
    def OnIdle(self, event):
      if self.reInitBuffer:
        self.InitBuffer()
        self.Refresh(False)
    
    def OnPaint(self, event):
      dc = wx.BufferedPaintDC(self, self.buffer)
      
    def DrawLines(self, dc):
      for colour, thickness, line in self.lines:
        pen = wx.Pen(colour, thickness, wx.SOLID)
        dc.SetPen(pen)
        for coords in line:
          dc.DrawLine(*coords)
    
    def SetColor(self, color):
      self.color = color
      self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
      
    def SetThickness(self, num):
      self.thickness = num
      self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
      
class PaintFrame(wx.Frame):
  def __init__(self, parent):
    wx.Frame.__init__(self, parent, -1, "Panit Frame", size = (800, 600))
    self.paint = PaintWindow(self, -1)
    
if __name__ == '__main__':
  app = wx.PySimpleApp()
  frame = PaintFrame(None)
  frame.Show(True)
  app.MainLoop()

测试:

wxPython实现绘图小例子

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
wxPython,绘图

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?