猫史档案馆


【Python作品分享】用左键、右键and滚轮来绘画【作品秀】

用户:宇宙中的星系宇宙中的星系查看:0 回复:0 评论:0 创建时间:2023-08-09T23:43:27


【作品展示】

center_image

 

【作品介绍】

与前者不同的是,它能用左键。右键and滚轮绘画

 

【作品源代码】

import pygame

pygame.init()
screen = pygame.display.set_mode([800,600])
red = (255,0,0)
keep_going = True
radius = 15
green = (0,255,0)
purple = (0,0,225)
mousebutton = False
pygame.display.set_caption("在点击的位置绘制圆点")
while keep_going:
    for event in pygame.event.get():
        if (event.type == pygame.QUIT):
            keep_going = False
        if (event.type == pygame.MOUSEBUTTONDOWN):
            mousebutton = True
        if (event.type == pygame.MOUSEBUTTONUP):
            mousebutton = False
    if (mousebutton == True):
        spot = pygame.mouse.get_pos()
        if pygame.mouse.get_pressed()[0]:
            c = red
        if pygame.mouse.get_pressed()[1]:
            c = green
        if pygame.mouse.get_pressed()[2]:
            c = purple
        pygame.draw.circle(screen,c,spot,radius)
    pygame.display.update()
pygame.quit()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页