[英]Python pygame need help on drawing rectangles
我試圖使用 python 的 pygame 模塊繪制一個矩形,我真的不知道我做錯了什么
import pygame
import sys
white = 255, 255, 255
red = 255, 0, 0
blue = 0, 0, 255
green = 0, 255, 0
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption('Rectangle test')
isRunning = pygame.get_init
while isRunning:
pygame.display.update()
pygame.event.get()
for event in pygame.event.get():
if event.type == pygame.QUIT:
isRunning = False
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
print(pygame.mouse.get_pos())
pygame.draw.rect(win, blue, (269, 165, 15, 15), 1)
win.fill((255, 255, 255))
pygame.quit()
這就是我當前使用的代碼,它打開了 window,window 填充正常工作,event.get 也工作,它打印它應該打印的內容,但它不繪制任何矩形
您填充的 window 正在消除您的矩形。 只需按相反的順序進行兩次調用:
win.fill((255, 255, 255))
pygame.draw.rect(win, blue, (269, 165, 15, 15), 1)
你會看到你的矩形。 當我應用此更改運行您的代碼時,我會這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.