首先,我建议你去PyGame文档并阅读一下PyGame。 (Link)
但是为了节省您的时间,您必须在屏幕上绘制新的形状/文字之前,必须使用功能screen.fill(#Your chosen colour)。这是PyGame中的功能,它可以摆脱旧屏幕,并允许您将新项目绘制到清晰的屏幕上,而不需要在那里留下透视图。
实施例:
import pygame
import sys
from pygame.locals import *
white = (255,255,255)
black = (0,0,0)
red = (255, 0, 0)
class Pane(object):
def __init__(self):
pygame.init()
self.font = pygame.font.SysFont('Arial', 25)
pygame.display.set_caption('Box Test')
self.screen = pygame.display.set_mode((600,400), 0, 32)
self.screen.fill((white))
pygame.display.update()
def addRect(self):
self.rect = pygame.draw.rect(self.screen, (black), (175, 75, 200, 100), 2)
pygame.display.update()
def addText(self):
self.screen.blit(self.font.render('Hello!', True, black), (200,