Привет, хотелось бы чтобы по нажатию на кнопку "Play" появилось новое окно с другим размером, как привязать функцию к кнопке?
Вот код:
Вот код:
Python:
import pygame
pygame.init()
display = pygame.display.set_mode((1024, 750))
pygame.display.set_caption("Breath of Two")
FPS = 60
font = pygame.font.SysFont("comicsansms", 30)
clock = pygame.time.Clock()
GREY = (105, 105, 105)
ORANGE = (255, 165 ,0)
pygame.mixer.music.load("sounds/smenu.mp3")
pygame.mixer.music.play(-1)
press_button_menu = pygame.mixer.Sound("sounds/press.sound.mp3")
#text_menu1= font.render("Новая эпидемия может стать концом для человечества",1,GREY,ORANGE)
#img_streets = pygame.image.load("photo/streets.png")
img_menu = pygame.image.load("photo/menu.png")
def menu():
menu_bckgr = pygame.image.load("photo/menu.png")
start_button = Button(220, 70)
titre_button = Button(220, 70)
show = True
while show:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
display.blit(menu_bckgr,(0, 0))
start_button.draw(750, 240, "Play")
titre_button.draw(750, 320, "Authors")
pygame.display.update()
clock.tick(60)
def print_text(message, x, y, font_color=(0, 0, 0), font_type="fonts/Futuram.ttf", font_size=30):
font_type = pygame.font.Font(font_type,font_size)
text = font_type.render(message, True, font_color)
display.blit(text, (x, y))
class Button:
def __init__(self, width, height):
self.width = width
self.height = height
self.inactive_color = (105, 105, 105)
self.active_color = (128, 128, 128)
def draw(self, x, y, message, action=None, font_size=30):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x < mouse[0] < x + self.width and y < mouse[1] < y + self.height:
pygame.draw.rect(display, self.active_color, (x, y, self.width, self.height))
if click[0] == 1 and action is not None:
#pygame.mixer.Sound.play(press_button_menu)
pygame.time.delay(300)
action()
else:
pygame.draw.rect(display, self.inactive_color, (x, y, self.width, self.height))
print_text(message=message, x=x + 60, y=y + 20, font_size=font_size,font_color=(255, 255, 255))
menu()
while exit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit = False
pygame.display.update()
pygame.quit()
Последнее редактирование: