我想创建某种图书馆(教育项目)。请告诉我,当您单击按钮时,是否可以在pygame窗口中显示 pdf(或 doc、txt)文件的文本?
或者单击按钮时打开此文件。
我尝试了在互联网上找到的所有选项,但要么我破坏了编写代码的顺序,要么我没有正确理解它。
当您单击“K_button我想反映文件或文件的内容”时。
代码片段:
import pygame
import sys
from Button import ImageButton
pygame.init()
screen = pygame.display.set_mode((1024, 670))
pygame.display.set_caption("Собственность")
icon = pygame.image.load("image/8920844.png")
pygame.display.set_icon(icon)
#Картинка фона
bg = pygame.image.load("image/XXL.png")
def theft158():
home_button = ImageButton(10, 5, 35, 35, "", "image/Домой.png", "image/Домой2.png")
back_button = ImageButton(45, 5, 40, 40, "", "image/Назад.png", "image/Назад2.png")
K_button = ImageButton(20, 105, 1024, 30, "Астраханский областной суд", "image/Статьи.png", "image/Статья2.png")
running = True
while running:
screen.fill((0, 0, 0))
screen.blit(bg, (0, 0))
home_button.check_hover(pygame.mouse.get_pos())
home_button.draw(screen)
back_button.check_hover(pygame.mouse.get_pos())
back_button.draw(screen)
K_button.check_hover(pygame.mouse.get_pos())
K_button.draw(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
home_button.handle_event(event)
back_button.handle_event(event)
if event.type == pygame.USEREVENT and event.button == home_button:
main_menu()
if event.type == pygame.USEREVENT and event.button == back_button:
sud_menu()
if event.type == pygame.USEREVENT and event.button == K_button:
pass
if __name__ == "__main__":
main_menu()