淘先锋技术网

首页 1 2 3 4 5 6 7

import pygame
from pygame.locals import *
pygame.init()
screenWidth,screenHeight=480,360
screen = pygame.display.set_mode((screenWidth,screenHeight))
pygame.display.set_caption("python画板(待改进)_作者:李兴球")

class Pen():
    def __init__(self,color,thickness):
        self.color = color         #笔颜色
        self.thickness = thickness #笔迹宽度
        self.status = 0         #笔的状态,是落笔还是抬笔

class Block():
    def __init__(self,clock):
        pass
    
def main():
    画板 = pygame.image.load("画板.png")
     
    pen  = Pen((255,0,0),2)
    clock = pygame.time.Clock()
    运行中 = True
    
    while 运行中:
        for event in pygame.event.get():
            if event.type==QUIT:运行中=False
            if event.type == MOUSEBUTTONDOWN:
                pen.status = 1
            if event.type ==MOUSEBUTTONUP:
                pen.status =0       
        
        mx,my = pygame.mouse.get_pos()        
        
        if pen.status == 1:
            pygame.draw.circle(画板,pen.color,(mx,my),pen.thickness)
            
        screen.blit(画板,(0,0))
        pygame.display.update()      
        pygame.display.set_caption(str(mx) + "," + str(my) + ":" + str(pen.status)) #x范围:115-440,y范围:83,323
        clock.tick(30)
    pygame.quit()

if __name__=="__main__":
    main()