Can't open PNG file using pygame












0














This is what I have so far, I'm trying to access a png file to display as the fret, but everything I've tried so far has pushed an error. The png file is in the same CWD as the .py file I'm running so that shouldn't be the issue. I'm on windows if that helps



import sys
import os
import pygame
from pygame.locals import *
import random
import notes
import frets
import score

class Controller:
def __init__(self):
pygame.init()
pygame.font.init()
self.width = 500
self.height = 300
self.screen = pygame.display.set_mode((self.width, self.height))
self.background = pygame.Surface(self.screen.get_size()).convert()
self.frets = pygame.sprite.Group()
self.frets.add(frets.Frets(100, 100, "openGreenFret.png"))

self.state = "GAME"

def mainLoop(self):
while True:
if(self.state == "GAME"):
self.gameLoop()
elif(self.state == "GAMEOVER"):
self.gameOver()


This is the class that is being used in the controller



    import pygame
class Frets(pygame.sprite.Sprite):
def __init__(self, x, y, img_file):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load(img_file).convert_alpha()

self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y


This is the error im getting in the terminal



Traceback (most recent call last):
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 6, in <module>
main()
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 4, in main
main_window = Controller.Controller()
File "C:UsersMatt FosterDocumentsController.py", line 19, in __init__
self.frets.add(os.path.join(frets.Frets(100, 100, "openGreenFret.png")))
File "C:UsersMatt FosterDocumentsfrets.py", line 6, in __init__
self.image = pygame.image.load(img_file).convert_alpha()
pygame.error: Couldn't open openGreenFret.png









share|improve this question


















  • 3




    Will even the most minimal code produce this error? If so you should just post that code, there's no reason to include anything unrelated. Anyway though, have you verified that you can get it to work with any image at all? Like, have you tried reproducing a really basic tutorial or example and found that that worked, but that your code still doesn't?
    – Random Davis
    Nov 12 at 22:24










  • This error usually means that the file name or the path are incorrect. Please print os.listdir() in your program.
    – skrx
    Nov 13 at 22:20
















0














This is what I have so far, I'm trying to access a png file to display as the fret, but everything I've tried so far has pushed an error. The png file is in the same CWD as the .py file I'm running so that shouldn't be the issue. I'm on windows if that helps



import sys
import os
import pygame
from pygame.locals import *
import random
import notes
import frets
import score

class Controller:
def __init__(self):
pygame.init()
pygame.font.init()
self.width = 500
self.height = 300
self.screen = pygame.display.set_mode((self.width, self.height))
self.background = pygame.Surface(self.screen.get_size()).convert()
self.frets = pygame.sprite.Group()
self.frets.add(frets.Frets(100, 100, "openGreenFret.png"))

self.state = "GAME"

def mainLoop(self):
while True:
if(self.state == "GAME"):
self.gameLoop()
elif(self.state == "GAMEOVER"):
self.gameOver()


This is the class that is being used in the controller



    import pygame
class Frets(pygame.sprite.Sprite):
def __init__(self, x, y, img_file):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load(img_file).convert_alpha()

self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y


This is the error im getting in the terminal



Traceback (most recent call last):
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 6, in <module>
main()
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 4, in main
main_window = Controller.Controller()
File "C:UsersMatt FosterDocumentsController.py", line 19, in __init__
self.frets.add(os.path.join(frets.Frets(100, 100, "openGreenFret.png")))
File "C:UsersMatt FosterDocumentsfrets.py", line 6, in __init__
self.image = pygame.image.load(img_file).convert_alpha()
pygame.error: Couldn't open openGreenFret.png









share|improve this question


















  • 3




    Will even the most minimal code produce this error? If so you should just post that code, there's no reason to include anything unrelated. Anyway though, have you verified that you can get it to work with any image at all? Like, have you tried reproducing a really basic tutorial or example and found that that worked, but that your code still doesn't?
    – Random Davis
    Nov 12 at 22:24










  • This error usually means that the file name or the path are incorrect. Please print os.listdir() in your program.
    – skrx
    Nov 13 at 22:20














0












0








0







This is what I have so far, I'm trying to access a png file to display as the fret, but everything I've tried so far has pushed an error. The png file is in the same CWD as the .py file I'm running so that shouldn't be the issue. I'm on windows if that helps



import sys
import os
import pygame
from pygame.locals import *
import random
import notes
import frets
import score

class Controller:
def __init__(self):
pygame.init()
pygame.font.init()
self.width = 500
self.height = 300
self.screen = pygame.display.set_mode((self.width, self.height))
self.background = pygame.Surface(self.screen.get_size()).convert()
self.frets = pygame.sprite.Group()
self.frets.add(frets.Frets(100, 100, "openGreenFret.png"))

self.state = "GAME"

def mainLoop(self):
while True:
if(self.state == "GAME"):
self.gameLoop()
elif(self.state == "GAMEOVER"):
self.gameOver()


This is the class that is being used in the controller



    import pygame
class Frets(pygame.sprite.Sprite):
def __init__(self, x, y, img_file):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load(img_file).convert_alpha()

self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y


This is the error im getting in the terminal



Traceback (most recent call last):
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 6, in <module>
main()
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 4, in main
main_window = Controller.Controller()
File "C:UsersMatt FosterDocumentsController.py", line 19, in __init__
self.frets.add(os.path.join(frets.Frets(100, 100, "openGreenFret.png")))
File "C:UsersMatt FosterDocumentsfrets.py", line 6, in __init__
self.image = pygame.image.load(img_file).convert_alpha()
pygame.error: Couldn't open openGreenFret.png









share|improve this question













This is what I have so far, I'm trying to access a png file to display as the fret, but everything I've tried so far has pushed an error. The png file is in the same CWD as the .py file I'm running so that shouldn't be the issue. I'm on windows if that helps



import sys
import os
import pygame
from pygame.locals import *
import random
import notes
import frets
import score

class Controller:
def __init__(self):
pygame.init()
pygame.font.init()
self.width = 500
self.height = 300
self.screen = pygame.display.set_mode((self.width, self.height))
self.background = pygame.Surface(self.screen.get_size()).convert()
self.frets = pygame.sprite.Group()
self.frets.add(frets.Frets(100, 100, "openGreenFret.png"))

self.state = "GAME"

def mainLoop(self):
while True:
if(self.state == "GAME"):
self.gameLoop()
elif(self.state == "GAMEOVER"):
self.gameOver()


This is the class that is being used in the controller



    import pygame
class Frets(pygame.sprite.Sprite):
def __init__(self, x, y, img_file):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load(img_file).convert_alpha()

self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y


This is the error im getting in the terminal



Traceback (most recent call last):
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 6, in <module>
main()
File "C:UsersMatt FosterDocumentsguitarHeroMain.py", line 4, in main
main_window = Controller.Controller()
File "C:UsersMatt FosterDocumentsController.py", line 19, in __init__
self.frets.add(os.path.join(frets.Frets(100, 100, "openGreenFret.png")))
File "C:UsersMatt FosterDocumentsfrets.py", line 6, in __init__
self.image = pygame.image.load(img_file).convert_alpha()
pygame.error: Couldn't open openGreenFret.png






python pygame png






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 22:11









Matt Foster

11




11








  • 3




    Will even the most minimal code produce this error? If so you should just post that code, there's no reason to include anything unrelated. Anyway though, have you verified that you can get it to work with any image at all? Like, have you tried reproducing a really basic tutorial or example and found that that worked, but that your code still doesn't?
    – Random Davis
    Nov 12 at 22:24










  • This error usually means that the file name or the path are incorrect. Please print os.listdir() in your program.
    – skrx
    Nov 13 at 22:20














  • 3




    Will even the most minimal code produce this error? If so you should just post that code, there's no reason to include anything unrelated. Anyway though, have you verified that you can get it to work with any image at all? Like, have you tried reproducing a really basic tutorial or example and found that that worked, but that your code still doesn't?
    – Random Davis
    Nov 12 at 22:24










  • This error usually means that the file name or the path are incorrect. Please print os.listdir() in your program.
    – skrx
    Nov 13 at 22:20








3




3




Will even the most minimal code produce this error? If so you should just post that code, there's no reason to include anything unrelated. Anyway though, have you verified that you can get it to work with any image at all? Like, have you tried reproducing a really basic tutorial or example and found that that worked, but that your code still doesn't?
– Random Davis
Nov 12 at 22:24




Will even the most minimal code produce this error? If so you should just post that code, there's no reason to include anything unrelated. Anyway though, have you verified that you can get it to work with any image at all? Like, have you tried reproducing a really basic tutorial or example and found that that worked, but that your code still doesn't?
– Random Davis
Nov 12 at 22:24












This error usually means that the file name or the path are incorrect. Please print os.listdir() in your program.
– skrx
Nov 13 at 22:20




This error usually means that the file name or the path are incorrect. Please print os.listdir() in your program.
– skrx
Nov 13 at 22:20

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270836%2fcant-open-png-file-using-pygame%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270836%2fcant-open-png-file-using-pygame%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word