D
D
Denis Kulikov2021-11-20 19:20:32
pygame
Denis Kulikov, 2021-11-20 19:20:32

It throws an error when creating a pygame_gui test button, how to fix this?

I am making a menu for the game and getting acquainted with pygame_gui along the way. When creating the first test button, an error immediately appeared

Traceback (most recent call last):
  File "C:\Users\Людмила\Desktop\Программирование\RPG\rpg.py", line 29, in <module>
    manager=manager)
  File "C:\Users\Людмила\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame_gui\elements\ui_button.py", line 116, in __init__
    self.rebuild_from_changed_theme_data()
  File "C:\Users\Людмила\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame_gui\elements\ui_button.py", line 539, in rebuild_from_changed_theme_data
    self.rebuild()
  File "C:\Users\Людмила\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame_gui\elements\ui_button.py", line 611, in rebuild
    'selected', 'active'], self.ui_manager)
  File "C:\Users\Людмила\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame_gui\core\drawable_shapes\rect_drawable_shape.py", line 35, in __init__
    self.full_rebuild_on_size_change()
  File "C:\Users\Людмила\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame_gui\core\drawable_shapes\rect_drawable_shape.py", line 90, in full_rebuild_on_size_change
    self.compute_aligned_text_rect()
  File "C:\Users\Людмила\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame_gui\core\drawable_shapes\drawable_shape.py", line 291, in compute_aligned_text_rect
    self.theming['font'].size(self.theming['text']))
AttributeError: 'NoneType' object has no attribute 'size'

Here is my code
import pygame
import random
from os import path
import pygame_gui 
from win32api import GetSystemMetrics
from menu import menu, check_menu

FPS = 60
#Цвета
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
#Ширина и высота для размещения спрайтов 
WIDTH = GetSystemMetrics(0)
HEIGHT = GetSystemMetrics(1)	

#Переменная для проверки выхода из игры(на данный момент просто нажатие на esc)
check_menu = check_menu()	
#Переменная manager
manager = pygame_gui.UIManager((WIDTH, HEIGHT))
#Группа со всеми спрайтами
all_sprites = pygame.sprite.Group()
pygame.init()
pygame.mixer.init()
#Создание и параметры окна
screen = pygame.display.set_mode((0, 0), pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.FULLSCREEN)
#Часы 
clock = pygame.time.Clock()
#Проверка запуска меню
game_over = True
#Тестовая кнопка
hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((WIDTH/2, HEIGHT/2), (100, 50)),
                      text='Say Hello!',
                      manager=manager)

running = True
while running:
  time_delta = clock.tick(60)/1000.0
  #Меню
  if game_over:
    menu()
  #Проверка вышел ли пользователь из игры
  if not check_menu:
    running = False
  clock.tick(FPS)	
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False

    manager.process_events(event)
  manager.update(time_delta)

  #Рендеринг
  screen.fill(BLACK)
  manager.draw_ui(screen)
  pygame.display.flip()

pygame.quit()
ттттььь

I went into the file, which, according to the interpreter, had an error, and ... got confused. It seems that the functions are familiar, but the further I read, the more I get confused.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question