Pygame Sprite Glitch - python

Hi can anyone help. I am getting glitching on pygame sprite. The sprites are 50x50 pixels 72 res created in Photoshop. I am using:
tile.image = pygame.image.load(tile.name) to load adding them to a pygroup tileGroup.add(tile) then just doing a regular tileGroup.draw(screen)
I have tried the code on a Windows PC and it works fine. I can only assume it is a MAC thing. Can anyone shed any light?

I had the same problem and I fixed it by downgrading from SDL v1.2.15 to 1.2.10. SDL Library has this nasty bug exclusively on El Capitan and on versions higher than 1.2.10.
To downgrade via Homebrew, you should:
Go to "/usr/local/Library/Formula", find "sdl_image.rb" and rename it to something in case to backup it.
In Terminal, use "brew create https://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.10.tar.gz". It should create new "sdl_image.rb" in the same location.
Open the new "sdl_image.rb" and the old one; Copy the lines that starts with "depends_on" and whole "install" function from the old image file and then replace "install" function in the new file with these lines.
In Terminal, use "brew install sdl_image".

This also sometimes happens with the Tkinter module, and mostly on mac (when you draw things on the screen it lgitches a lot.)
I believe it is a mac problem, so you could try the following:
You could use a different image,
you could .convert() the image
you could .convert_alpha() the image

Related

I need to detect pixel color on screen using python on Mac OS X

I usually program on PC so I'm pretty new to using Mac python libraries. I would like to detect the color of a pixel at the cursors current location without clicking. On PC, I have a something that works using the below code:
pyautogui.moveTo(xcoord,ycoord,1)
x,y=pyautogui.position()
RGBVal=pyautogui.pixel(x,y)
A lot of the tools I have found when searching bring up a new hud that reads out the rgb value. This wont work as the program will move the mouse on the screen and click based on the colors it sees so I can't have the display window on top. The 2 leads I had that were somewhat promising were PIL where I was trying something like this:
rgb = PIL.ImageGrab.grab().load()[pilx,pily]
The issue here is that the coordinates weren't lining up. I tested with a pure red window and it didn't detect that it was in the square until I had the y value at ~3 times the value expected. I was assuming top left corner is 0,0 but tried with inverted y axis and things still weren't lining up properly.
The other attempt I had was using autopy. I was originally having install issues because I was running on python version 3.10. I have downgraded and now see Python 3.7.14 when I use python3 --version. I was able to download and install autopy and when I try again with pip3 it shows "Requirement already satisfied" but when trying to run my code I get a "No module named 'autopy'" error at my "import autopy" line.
If anyone knows how I can make PIL or autopy work or some third option it would be greatly appreciated.

How do I get Pillow ImageOps.contain to work when inside VS Code?

I have VS Code on a Mac.
Pillow is installed and version verified as 8.3.2 via Pip list in the terminal window of VS Code. I have confirmed via the pillow docs that the ImageOps.contain() is part of 8.3.
My problem is that when I use the terminal, type python and run the following, it works perfectly:
from PIL import Image, ImageOps
im = Image.open("images/Barcelona.jpg")
print(im.format, im.size, im.mode)
im = ImageOps.contain(im, (800, 800), method=3)
im.show()
Preview pops right up and shows me the picture.
When I put the exact code into VS Code or build a .py file with Nano, I get an error message which is shown in this image:
I've verified the right version of Python, Pillow, and such. Any help or pointers would be greatly appreciated.
This turns out to be a problem with what I can only call nested environments and/or a conflict between Anaconda and Workspaces. I'm not really sure but when I used the _version import to figure out a) what VS Code thought and then b) figured out the environment Pip was reporting on, I deactivated up one level, upgraded the (base) to the 8.3 version and all ran fine. The knowledge on importing the version variable to see precisely what the code is importing came from the question asked below and was invaluable.

Is there a way to capture an image of the screen in python with ctypes?

I want to have python save an image file of the whole screen as a variable with ctypes so that I could access the screen in a program and do something with it (like put it on a pygame window). I can't use any other libraries unless they are included with python (no installing or pip). Does anyone know how to do this?
Edit: I'm using windows 10.
PIL.ImageGrab is from PILLOW (a python image library fork which you can install with pip). You can give a bounding box or capture the entire screen.
Update: OP now mentions he can't use external libraries.
Then you could virtually hit printscreen and read the clipboard. The code of PILLOW is open-source feel free to use it.
Remember that you can always call a command from within python:
>>> import os
>>> os.system("pip install pillow")
Or download the zip of the library and import it in your code.

Installing csv package in pycharm 3.6

i use windows and pycharm 3.6
and for some reason i can't import the csv package to my code.
it just goes gray
tried to use pip to install, didn't work.
if someone can help or otherwise recommend a different package that does the same thing, it would be highly appreciated.
Unless csv has a red underline, the grey foreground color simply means you haven't used that module in your project yet. If you mouse over it, it will indicate Unused import statement more...

Getting Aspen and Gheat on Windows working

I am not really familiar Python setup, I am trying to get gheat running on a Windows box, and it tells me it can't find pygame.
I have tried Python25,26, older pygame version too.
I have installed those as well as numpy as it has a dependency.
Could someone with experience try and help me out getting it up and running.
I have tried running Process Monitor against it, and it seems to find all the files etc but aspen/gheat still tell me it can't find Pygame.
Links below.
1.) http://www.python.org/
2.) http://code.google.com/p/gheat/
3.) http://www.pygame.org/
4.) Link
Cheers for any help.
Aside, It works fine on my ubuntu box just by install pygame and it works !
With thanks to SeC- from the #csharp channel on Freenode, he figured out it is the problem with the latest trunk of aspen, (I thought I'd tried the older version)
http://www.zetadev.com/software/aspen/0.8/dist/aspen-0.8.zip
You will need the 0.8 version to get it working!!
Cheers anyway!

Categories