小编use*_*944的帖子

Pygame:如何更改背景颜色

import pygame, sys
pygame.init()
screen = pygame.display.set_mode([800,600])
white = [255, 255, 255]
red = [255, 0, 0]
screen.fill(white)
pygame.display.set_caption("My program")
pygame.display.flip()



background = input("What color would you like?: ")
if background == "red":
    screen.fill(red)

running = True
while running:
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
        running = False
        pygame.quit()
Run Code Online (Sandbox Code Playgroud)

我试图询问用户他想要什么背景颜色。如果用户写红色,颜色不会改变并且仍然保持白色。

python pygame python-3.x

9
推荐指数
2
解决办法
5万
查看次数

pygame 新手。这个“for i in range”不起作用

from random import randint\nimport pygame, sys\npygame.init()\nekraan = pygame.display.set_mode([800, 600])\nvalge = [255, 255, 255]\nekraan.fill(valge)\npygame.display.set_caption("\xc3\x9clesanne 6")\npygame.display.flip()\n\n\nv\xc3\xa4rv1 = randint(0, 255)\nv\xc3\xa4rv2 = randint(0, 255)\nv\xc3\xa4rv3 = randint(0, 255)\nasukoht_x = randint(0, 800)\nasukoht_y = randint(0, 600)\nsuurus = randint(5, 100)\n\ni = 1\nfor i in range(100):\n    pygame.draw.circle(ekraan, (v\xc3\xa4rv1, v\xc3\xa4rv2, v\xc3\xa4rv3), [asukoht_x, asukoht_y], suurus, 0) \n    pygame.display.flip()\n    i = i + 1\n\n\n\nrunning = True\nwhile running:\n    for i in pygame.event.get():\n        if i.type == pygame.QUIT:\n            running = False\n            pygame.quit()\n
Run Code Online (Sandbox Code Playgroud)\n\n

我试图让程序绘制 100 个圆圈,每个圆圈都有随机颜色、随机 X、Y 坐标和随机大小。我正在使用 for i in range(100) 但它不起作用。该程序仅绘制 1 个圆圈,其中一切都是随机的。 …

python

0
推荐指数
1
解决办法
825
查看次数

标签 统计

python ×2

pygame ×1

python-3.x ×1