Defining a screen in PyGame and not show it - python

I'm writing a script on PyGame that should create an image and save it, not show it. The process of generating and saving is perfect, but when I use myscreen = pygame.display.set_mode([500,500]), it causes a windows to be open, on the size I'm defining. Once I'm not giving any pygame.display.flip() the window just blinks, appear and dissapear.
I would like to know if there is a way to initialize a screen in PyGame and not show it, so, I could create my image and just save it.

Don't use display to create it. You can just construct a Surface and use it in conjunction with image.save() to save it, or use something like Pillow to create an image without using PyGame at all.

Related

How FAST give opencv browser screen(selenium)?

There is a game, where if you want to play you need to look all screen(all screen is a - canvas). How can I give this canvas to opencv FAST(0.1 sec upd)? Now I simply make screenshots of screen with selenium(drive.save_screenshot("foo.png")) but this way is too slow(0.3-0.5 sec).
Is there any way to save screenshots faster or other way to give opencv access to screen or smth else. Maybe I need to save screenshot as bytes but not as file to upd canvas faster?
Also I found this https://python-mss.readthedocs.io/examples.html#part-of-the-screen but I didn't find how to use it with selenium. Python.
Photo of canvas:

Is there a way to take a "screenshot" in pygame, and then save it as a sprite so as to reduce code complexity?

The title says it all, although in my instance, the reason I wish to use this feature is I plan on having a all this stuff moving around, until I call this "dialogue()" function, when everything will stop, and I will have dialogue options moving about the screen. However, I don't want to continually render everything in the background, so is there some way of going about taking a screenshot in pygame?
You can capture the contents of the Pygame.Surface by making a copy with screen.copy() then when you want to redraw you use screen.blit(copy, (0,0)). And then you draw on top of that.
Another option is to change your code so that you render the background into a separate surface rather than copying it from the screen and then combine the foreground with the dialogue with it by bliting the background and then the foreground to the screen.
If this isn't right for you, please share more about your program. I haven't used Pygame in a while so this is mostly based on the documentation https://www.pygame.org/docs/ref/surface.html

adding a quit timer that closes a photo

After many hours of searching online and in my python book I can't seem to find the answer to my question which is what do I add to my code so I can put in a timer that automatically closes the photo? It pulls itself up but then I have to manually close the photo to get back to my main program. Any help would be appreciated.
from PIL import Image
img = Image.open('battleship load screen.png')
img.show()
This is not possible using PIL alone - img.show() is just launching another program, it's intended for debugging really, not for presenting things to the user.
From the docs.
Displays an image. This method is mainly intended for debugging
purposes.
On Unix platforms, this method saves the image to a temporary PPM
file, and calls the xv utility.
On Windows, it saves the image to a temporary BMP file, and uses the
standard BMP display utility to show it.
This method returns None.
If you want to display an image and have control over it, use a graphical toolkit and construct a UI for your purpose. I've linked there to an example using PySide, a set of QT bindings, but of course you could use any toolkit - each will be different.

Loading a multiframe/moving .gif image into python using pygame

Does anyone know a simple way to load a .gif image into python using pygame? I tried loading a .gif image using 'pygame.image.load(path)' which worked although only the first frame loaded.Ever since I had to use a loop to display multiple images at once.
Simply put, you cannot display multi-frame GIFs in Pygame, unless you use an extra library. Instead, explode your GIF. You will have to do everything manually, as Pygame does not control flow time, etc, which is necessary for animated GIFs.

How to set the screen resolution in pythoncard

I want to set the resolution of my application as per the resolution of the system screen its running on. i want to be on top and also in full screen covering even the taskbar as i am using windows. i want the app to open like the ATM interface, so the app should fill the entire screen.
please help me to find the solution.
thanks
The frame object has a "ShowFullScreen" method that you could use. I just tested it and it works alright, although it doesn't show the title bar of the app. I don't know if you care about that though.
EDIT: Uh, to call a method on the frame object, you would do something like
self.ShowFullScreen(True)
or
myFrame.ShowFullScreen(True)

Categories

Resources