Using a mac, I am trying to set the background of my program to an image that i downloaded, I called the image "ChristmasBackground.jpg" and saved it to my documents. Using Zelle graphics, this is what I wrote:
XmasBack = Image(Point(600,100),"ChristmasBackground.jpg")
XmasBack.draw(win)
but the program is giving me an error saying:
couldn't open "ChristmasBackground.jpg": no such file or directory
just put it in the same folder of your script or write the file path
Related
TLDR; I have a python script that uses autopygui to click on a file and open it, but it does not work with lnk files located in the same path.
I have a little script using pyautogui to screenshot a desktop icon and save it as a png image on the desktop and doubleclick it to open that image. This works perfect.
However..
I tried implementing the same script on an existing Firefox.lnk shortcut and it fails with the following error:
locateOnScreen Error
Things I have tried:
Running VS code as admin.
locateOnCenterScreen and locateOnScreen.
I have tried others, but I'm blanking because I have tried everything I can think of.
It should open my Firefox.lnk shortcut up, it does not. It only works on png file.
It's because the locateOnScreen(...) function only accepts paths to image files, and .lnk files are not image files. If you manually took a screenshot of the Firefox icon on your desktop, saved it as a PNG file, and passed that to your script, it would open fine.
If you want to launch a program using a .lnk file from Python, you don't need pyautogui at all. Consider using os.startfile(...) instead.
You should put the path of png file in locateCenterOnScreen(...) function instead.
Please also make sure you minimize all active windows so that pyautogui could locate your Firefox short icon.
import pyautogui
pyautogui.hotkey('winleft','d')
icon_location = pyautogui.locateCenterOnScreen('.../FireFox_icon_screenshot.png', confidence=0.9)
pyautogui.moveTo(icon_location)
pyautogui.click(clicks=2)
I am trying a simple Computer Vision program with OpenCV. After creating the Python file, I run it through Jupyter Lab directly on the Terminal to avoid bugs. However, it opens a python3 file (not an image) and I cannot see the image.
I have tried the following:
Step 1: Terminal
Step 2: File not responding
Do you have any clue why this is happening?
Following an online game building tutorial on Youtube, I am trying to build a game but whenever i enter this code it always comes out with this syntax error:
line 11, in <module>
icon = pygame.image.load('burger.png')
pygame.error: Couldn't open burger.png
what should I do?
Probably nothing to do with Pygame itself. But your file location. Do you have it in the same folder as your .py script (aka your root folder)? If yes, check this thread out: Opening images with Python
I was using the turtle module with Python to make a project. In the project, an image is displayed, with this line:
screen.bgpic("image.png")
This worked at first, but then I copied the files (both the python file and image.png) onto a flash drive. I tested it on another computer, and it worked fine there, but when I saved it onto the actual computer that I needed it to be on, it didn't work.
I know it's not a problem with the actual turtle, since it works before that part. I also am pretty sure it isn't a file problem since the same file worked before. It says:
Couldn't recognize data in image file "image.png"
Older versions of tkinter don't support .png files.
You can convert GIF or JPEG or another image file type with an external tool.
I have a hangman style program that calls on Pillows to display images, but instead it just opens a python process as depicted in the images while displaying nothing:
I've installed Pillows successfully, and running the program on a Windows PC with WinPy opens the image.