J'essaye de charger une image en vain
Résolu/Fermé
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
-
7 mai 2021 à 01:47
Clawzix Messages postés 7 Date d'inscription vendredi 7 mai 2021 Statut Membre Dernière intervention 7 mai 2021 - 7 mai 2021 à 11:08
Clawzix Messages postés 7 Date d'inscription vendredi 7 mai 2021 Statut Membre Dernière intervention 7 mai 2021 - 7 mai 2021 à 11:08
A voir également:
- J'essaye de charger une image en vain
- Image iso - Guide
- Comment agrandir une image - Guide
- Acronis true image - Télécharger - Sauvegarde
- Image de profil - Guide
- Faststone image viewer - Télécharger - Visionnage & Diaporama
4 réponses
Whismeril
Messages postés
19028
Date d'inscription
mardi 11 mars 2003
Statut
Non membre
Dernière intervention
24 avril 2024
931
7 mai 2021 à 06:50
7 mai 2021 à 06:50
Bonjour
Non, cette image ne permet pas de t’aider.
Déjà pour poster ton code, il faut faire comme décrit là https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Et c’est super important en Python, sinon, le site ne conserve pas l’indentation.
Non, cette image ne permet pas de t’aider.
Déjà pour poster ton code, il faut faire comme décrit là https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Et c’est super important en Python, sinon, le site ne conserve pas l’indentation.
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
7 mai 2021 à 09:57
7 mai 2021 à 09:57
import pygame as p
from Chess import ChessEngine
p.init()
WIDTH = HEIGHT = 512
DIMENSION = 8
SQ_SIZE = HEIGHT // DIMENSION
MAX_FPS = 15
IMAGES = {}
def loadImages():
pieces = ["bB", "bK", "bN", "bp", "bQ", "bR", "wB", "wK", "wN", "wp", "wQ", "wR"]
for piece in pieces:
IMAGES[piece] = p.transform.scale(p.image.load("images/" + piece + ".png"), (SQ_SIZE, SQ_SIZE))
def main():
p.init()
screen = p.display.set_mode((WIDTH, HEIGHT))
clock = p.time.Clock()
screen.fill(p.Color("white"))
gs = ChessEngine.GameState()
loadImages()
running = True
while running:
for e in p.event.get():
if e.type == p.QUIT:
running = False
drawGameState(screen, gs)
clock.tick(MAX_FPS)
p.display.flip()
def drawGameState(screen, gs):
drawBoard(screen)
drawPieces(screen, gs.board)
def drawBoard(screen):
colors = [p.Color("white"), p.Color("gray")]
for r in range(DIMENSION):
for c in range(DIMENSION):
color = colors[((r+c) % 2)]
p.draw.rect(screen, color, p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
def drawPieces(screen, board):
for r in range(DIMENSION):
for c in range(DIMENSION):
piece = board[r][c]
if piece != "--":
screen.blit(IMAGES[piece], p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
if __name__ == "__main__":
main()
Excuse moi j'aurai du regarder comment faire avant de publier mon problème
from Chess import ChessEngine
p.init()
WIDTH = HEIGHT = 512
DIMENSION = 8
SQ_SIZE = HEIGHT // DIMENSION
MAX_FPS = 15
IMAGES = {}
def loadImages():
pieces = ["bB", "bK", "bN", "bp", "bQ", "bR", "wB", "wK", "wN", "wp", "wQ", "wR"]
for piece in pieces:
IMAGES[piece] = p.transform.scale(p.image.load("images/" + piece + ".png"), (SQ_SIZE, SQ_SIZE))
def main():
p.init()
screen = p.display.set_mode((WIDTH, HEIGHT))
clock = p.time.Clock()
screen.fill(p.Color("white"))
gs = ChessEngine.GameState()
loadImages()
running = True
while running:
for e in p.event.get():
if e.type == p.QUIT:
running = False
drawGameState(screen, gs)
clock.tick(MAX_FPS)
p.display.flip()
def drawGameState(screen, gs):
drawBoard(screen)
drawPieces(screen, gs.board)
def drawBoard(screen):
colors = [p.Color("white"), p.Color("gray")]
for r in range(DIMENSION):
for c in range(DIMENSION):
color = colors[((r+c) % 2)]
p.draw.rect(screen, color, p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
def drawPieces(screen, board):
for r in range(DIMENSION):
for c in range(DIMENSION):
piece = board[r][c]
if piece != "--":
screen.blit(IMAGES[piece], p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
if __name__ == "__main__":
main()
Excuse moi j'aurai du regarder comment faire avant de publier mon problème
yg_be
Messages postés
22724
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
25 avril 2024
1 476
7 mai 2021 à 10:20
7 mai 2021 à 10:20
bonjour, il n'est pas trop tard pour lire les instructions et pour poster correctement ton code.
as-tu lu le message d'erreur? le comprends-tu?
as-tu lu le message d'erreur? le comprends-tu?
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
7 mai 2021 à 10:23
7 mai 2021 à 10:23
Je comprend que la fonctino p.image.load() n'arrive pas à trouver mon image avec les paramètres que je lui fournis
yg_be
Messages postés
22724
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
25 avril 2024
1 476
7 mai 2021 à 10:42
7 mai 2021 à 10:42
plus précisément, il ne trouve pas le fichier. il suffit donc de placer le fichier au bon endroit.
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
>
yg_be
Messages postés
22724
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
25 avril 2024
7 mai 2021 à 10:43
7 mai 2021 à 10:43
mais je pensais l'avoir mis au bon endroit :')
yg_be
Messages postés
22724
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
25 avril 2024
1 476
>
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
7 mai 2021 à 10:45
7 mai 2021 à 10:45
dans ce cas-là, c'est le programme qui a raison.
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
>
yg_be
Messages postés
22724
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
25 avril 2024
7 mai 2021 à 10:46
7 mai 2021 à 10:46
Je me doute mais je ne sais pas quoi faire.
yg_be
Messages postés
22724
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
25 avril 2024
1 476
>
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
7 mai 2021 à 10:51
7 mai 2021 à 10:51
suggestions: réfléchir, communiquer.
Exileur
Messages postés
1475
Date d'inscription
mercredi 31 août 2011
Statut
Membre
Dernière intervention
16 décembre 2022
150
Modifié le 7 mai 2021 à 11:00
Modifié le 7 mai 2021 à 11:00
import pathlib def loadImages(): pieces = ["bB", "bK", "bN", "bp", "bQ", "bR", "wB", "wK", "wN", "wp", "wQ", "wR"] for piece in pieces: IMAGES[piece] = p.transform.scale(p.image.load(str(pathlib.Path(__file__).parent.absolute()) + "/images/" + piece + ".png"), (SQ_SIZE, SQ_SIZE))
Exileur
Messages postés
1475
Date d'inscription
mercredi 31 août 2011
Statut
Membre
Dernière intervention
16 décembre 2022
150
7 mai 2021 à 11:07
7 mai 2021 à 11:07
Pour l'explication, ta lib python est surement installé qq part dans /usr/lib/pythonX.X/pygame et elle cherche surement les images dans /usr/lib/pythonX.X/pygame/images
Clawzix
Messages postés
7
Date d'inscription
vendredi 7 mai 2021
Statut
Membre
Dernière intervention
7 mai 2021
7 mai 2021 à 11:08
7 mai 2021 à 11:08
Merci beaucoup grâce à toi mon problème est résolu !