PygameGUI error loading libpng16-16.dll: the file cannot be accessed by the system

29 views Asked by At

In my pygame project using pygame and the library pygameGUI I can't load any pngs as the dll for doing it won't load.

Traceback (most recent call last):
  File "C:\Users\tomto\PycharmProjects\CasinoPy\main.py", line 82, in <module>
    test = pygame.image.load('Assets/Cards/2_of_Hearts.png')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pygame.error: Failed loading libpng16-16.dll: The file cannot be accessed by the system.

Process finished with exit code 1

I also installed libpng again but this has not worked either. Below is my code.

import pygame
import pygame_gui

from pygame_gui.core import ObjectID

import random
import sys

pygame.init()
RED = (255, 0, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SCREEN_SIZE = (1000, 600)
SUITS = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
VALUES = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'jack', 'queen', 'king', 'ace']
deck = []
screen = pygame.display.set_mode(SCREEN_SIZE)
pygame.display.set_caption("Casino")

clock = pygame.time.Clock()
running = True
manager = pygame_gui.UIManager(SCREEN_SIZE, 'button.json')
manager.get_theme().load_theme('label.json')


class Menu:
    def __init__(self):
        self.running = True
        self.title = pygame_gui.elements.UILabel(relative_rect=pygame.Rect((400, 100), (200, 50)),
                                                 text='Casino',
                                                 manager=manager,
                                                 object_id=ObjectID(class_id='@menuText', object_id='#title'))

        self.blackjackButton = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((400, 200), (200, 50)),
                                                            text='Blackjack',
                                                            manager=manager,
                                                            object_id=ObjectID(class_id='@menuButtons',
                                                                               object_id='#blackjackButton'))
        self.pokerButton = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((400, 300), (200, 50)),
                                                        text='Poker',
                                                        manager=manager,
                                                        object_id=ObjectID(class_id='@menuButtons',
                                                                           object_id='#pokerButton'))
        self.loginButton = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((400, 400), (200, 50)),
                                                        text='Login',
                                                        manager=manager,
                                                        object_id=ObjectID(class_id='@menuButtons',
                                                                           object_id='#loginButton'))

    def draw(self):
        while self.running:

            time_delta = clock.tick(60) / 1000.0
            screen.fill(WHITE)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = False

                if event.type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == self.blackjackButton:
                        print("Start Game")
                    elif event.ui_element == self.pokerButton:
                        pass
                manager.process_events(event)
            manager.update(time_delta)
            manager.draw_ui(screen)
            pygame.display.update()
            clock.tick(60)


class Card:
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value
        self.name = f'{value}_of_{suit}'
        self.imagePath = f'Assets/Cards/{self.name}.png'
        self.image = pygame.image.load(self.imagePath)


test = Card('Hearts', '2')
menu = Menu()
menu.draw()

I have tried copying the dll into various folders in the site-packages directory but I am not clued up in this at all.

0

There are 0 answers