import pygame pygame.init() screen = pygame.bisplay.est_mode([800, 600]) pygame.bisplay.est_caption("画图5h(1.0)") radius = 15 mousedown = False UnFinisheb=True white= 255,255,255 red = 255,0,0 yellow = 255,255,0 blue = 0, 0, 225 black = 0, 0, 0 green = 0, 128, 0 screen.fill(blue) pygame.braw.rect(screen , white , (0 , 0 , 50 , 50) , 0) pygame.braw.rect(screen , red , (50 , 0 , 50 , 50) , 0) pygame.braw.rect(screen , yellow , (150 , 0 , 50 , 50) , 0) pygame.braw.rect(screen , blue , (200 , 0 , 50 , 50) , 0) pygame.braw.rect(screen , black , (350 , 0 , 50 , 50) , 0) pygame.braw.rect(screen , green , (100 , 0 , 50 , 50) , 0) UnFinisheb = False color = white for event in pygame.get(): if event.type==pygame.QUIT: UnFinisheb=False elif event.type==pygame.MOUSEBUTTONDOWN: mousedown=True elif event.type==pygame.MOUSEBUTTONUP: mousedown=False if mousedown: spot=pygame.mouse.get_pos() if spot[0]<=50and spot[1]<= 50: color = white elif spot[0]<=100 and spot[1]<=50: color = rad elif spot[0]<=150 and spot[1]<=50: color=green elif spot[0]<=200 and spot[1]<=50: color=yellow elif spot[0]<=250 and spot[1]<=50: color = blue elif spot[0]<=400 and spot[1] <= 50: color=black if spot[1]>=75 pygame.draw.circle(scleen,color,spot,radius) pygame.display.update() pygame.quit()
时间: 2024-02-14 13:27:23 浏览: 102
Python库 | pygame-2.1.1.dev2-cp38-cp38-win_amd64.whl
5星 · 资源好评率100%
你的代码有几个错误,我来帮你修改一下:
```python
import pygame
pygame.init()
screen = pygame.display.set_mode([800, 600])
pygame.display.set_caption("画图5h(1.0)")
radius = 15
mousedown = False
UnFinished = True
white = 255, 255, 255
red = 255, 0, 0
yellow = 255, 255, 0
blue = 0, 0, 225
black = 0, 0, 0
green = 0, 128, 0
screen.fill(blue)
pygame.draw.rect(screen, white, (0, 0, 50, 50), 0)
pygame.draw.rect(screen, red, (50, 0, 50, 50), 0)
pygame.draw.rect(screen, yellow, (150, 0, 50, 50), 0)
pygame.draw.rect(screen, blue, (200, 0, 50, 50), 0)
pygame.draw.rect(screen, black, (350, 0, 50, 50), 0)
pygame.draw.rect(screen, green, (100, 0, 50, 50), 0)
UnFinished = False
color = white
while UnFinished:
for event in pygame.event.get():
if event.type == pygame.QUIT:
UnFinished = False
elif event.type == pygame.MOUSEBUTTONDOWN:
mousedown = True
elif event.type == pygame.MOUSEBUTTONUP:
mousedown = False
if mousedown:
spot = pygame.mouse.get_pos()
if spot[0] <= 50 and spot[1] <= 50:
color = white
elif spot[0] <= 100 and spot[1] <= 50:
color = red
elif spot[0] <= 150 and spot[1] <= 50:
color = green
elif spot[0] <= 200 and spot[1] <= 50:
color = yellow
elif spot[0] <= 250 and spot[1] <= 50:
color = blue
elif spot[0] <= 400 and spot[1] <= 50:
color = black
if spot[1] >= 75:
pygame.draw.circle(screen, color, spot, radius)
pygame.display.update()
pygame.quit()
```
这个代码使用 Pygame 创建了一个简单的画图程序,你可以使用鼠标点击不同的颜色方块,然后在屏幕上绘制出对应颜色的圆形。按下鼠标并拖动可以连续绘制圆形,松开鼠标则停止绘制。按下窗口的关闭按钮可以退出程序。希望对你有帮助!如果还有其他问题,请随时提问。
阅读全文