【发布时间】:2021-11-06 21:27:58
【问题描述】:
我知道已经有几个关于这个主题的问题,但不幸的是我还没有找到适合我的答案...
我正在尝试进行井字游戏,即使它正在运行,屏幕显示黑色或黑色并带有绿色虚线......
我已经尝试了不同的 pygame 版本,但没有帮助。 目前我正在使用:Pygame 2.0.3 (SDL 2.0.16, Python 3.8.3)
我的代码:
import pygame
from pygame.locals import *
pygame.init()
screen_width = 300
screen_height = 300
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('tic tac toe')
def draw_grid():
bg = (255, 0, 0)
grid = (50, 50, 50)
screen.fill(bg)
for x in range(1, 3):
pygame.draw.line(screen, grid, (0, x * 100), (screen_width, x * 100))
pygame.draw.line(screen, grid, (x * 100, 0), (x * 100, screen_height))
run = True
while run:
#add event handlers
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()
【问题讨论】:
-
draw_grid永远不会被调用。但是,当我调用draw_grid时,程序运行正常。