【发布时间】:2014-02-02 21:34:58
【问题描述】:
我正在使用 pygame 和 python 创建游戏。我在窗口中绘制了一个用作按钮的矩形。但是我需要知道如何在单击按钮后将其删除。这是我的代码:
import pygame, sys
from pygame.locals import *
x = 0
y = 0
#Basic stuff:
pygame.init()
screen=pygame.display.set_mode((640,360),0,32)
pygame.display.set_caption("Some random Title")
while True:
evc = pygame.event.get()
for event in evc:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
x,y = pygame.mouse.get_pos()
screen.lock()
#draw button:
my_rect = pygame.draw.rect(screen,(205,201,201),Rect((245,40),(130,80)))
bf1 = pygame.font.SysFont("monospace", 15)
bl = bf1.render("Play!!!", 1, (255, 255, 255))
screen.unlock()
#Check mouse click!!!
if my_rect.collidepoint(x,y):
for event in evc:
if event.type ==pygame.MOUSEBUTTONUP:
screen.fill((255,255,255))
screen.blit(bl, (280, 70))
pygame.display.flip
pygame.display.update()
所以是的,我希望你能帮助我。
【问题讨论】:
标签: python window pygame reset rect