I'm trying to make a GUI with pygame_gui
and pygame_gui
is throwing a error.
I made a simple GUI class like this:
import pygame
import pygame_gui
class GUI:
def __init__(self, window):
self.manager = pygame_gui.UIManager((window.w, window.h))
def init(self):
self.hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((0, 0), (100, 50)), text='UWU', manager=self.manager)
def process_events(self, event):
if event.type == pygame_gui.UI_BUTTON_PRESSED:
if event.ui_element == self.hello_button:
print("HI")
self.manager.process_events(event)
def update(self, dt):
self.manager.update(dt)
def render(self, window):
self.manager.draw_ui(window)
If you look at the pygame_gui docs this is the same just put in a class.
I'm getting this error:
Traceback (most recent call last):
File "C:\Users\jacki\OneDrive\Desktop\Coding\Python Projects\Uwu123\main.py", line 5, in <module>
engine = Engine("C:\\Users\\jacki\\OneDrive\\Desktop\\Coding\\Python Projects\\Uwu123\\assets")
File "C:\Users\jacki\OneDrive\Desktop\Coding\Python Projects\Uwu123\uwu123.py", line 18, in __init__
self.gui = GUI(self)
File "C:\Users\USER\OneDrive\Desktop\Coding\Python Projects\Uwu123\gui.py", line 6, in __init__
self.manager = pygame_gui.UIManager((engine.w, engine.h))
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\ui_manager.py", line 69, in __init__
self.ui_theme = UIAppearanceTheme(self.resource_loader, self._locale)
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\ui_appearance_theme.py", line 62, in __init__
self.font_dict = UIFontDictionary(self._resource_loader, locale)
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\ui_font_dictionary.py", line 128, in __init__
self._load_default_font()
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\ui_font_dictionary.py", line 156, in _load_default_font
error = default_font_res.load()
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\utility.py", line 395, in load
self.loaded_font = GUIFontFreetype(
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\gui_font_freetype.py", line 17, in __init__
self.__internal_font: Font = Font(file, size, resolution=72)
RuntimeError: The FreeType 2 library hasn't been initialized
I tried to install FreeType2
, but it didn't work because I couldn't find build instructions.
I found my issue my IDE (Pycharm) got mad at me and thought that pygame.freetype did not exist. So that's why I posted this question.