parent
c807c06d54
commit
19643ec94c
@ -0,0 +1,56 @@
|
||||
encoding="utf-8"
|
||||
import pygame
|
||||
|
||||
#encoding=utf-8
|
||||
# 初始化 pygame
|
||||
pygame.init()
|
||||
|
||||
# 设置屏幕尺寸
|
||||
screen_width = 800
|
||||
screen_height = 600
|
||||
screen = pygame.display.set_mode((screen_width, screen_height))
|
||||
|
||||
# 按钮颜色
|
||||
button_color = (0, 128, 255)
|
||||
|
||||
# 按钮文本
|
||||
button_text = "start"
|
||||
|
||||
# 字体设置
|
||||
font = pygame.font.SysFont(None, 36)
|
||||
|
||||
# 按钮位置和尺寸
|
||||
button_rect = pygame.Rect(240, 400, 300, 100)
|
||||
image = pygame.image.load("2.jpg")
|
||||
|
||||
|
||||
|
||||
# 将图片绘制到窗口上
|
||||
|
||||
# 主循环
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
# 检测鼠标点击事件
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if button_rect.collidepoint(event.pos):
|
||||
# 进入游戏的逻辑
|
||||
import pt
|
||||
|
||||
# 绘制背景
|
||||
screen.blit(image, (0, 0))
|
||||
|
||||
# 绘制按钮
|
||||
pygame.draw.rect(screen, button_color, button_rect)
|
||||
|
||||
# 绘制按钮文本
|
||||
text_surface = font.render(button_text, True, (255, 255, 255))
|
||||
text_rect = text_surface.get_rect(center=button_rect.center)
|
||||
screen.blit(text_surface, text_rect)
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
# 退出程序
|
||||
pygame.quit()
|
Loading…
Reference in new issue