This question already has answers here:
Is there any other way to load a resource like an image, sound, or font into Pygame? [closed]
(1 answer)
Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."
(1 answer)
Closed 2 years ago.
so I'm trying to make an application using pygame that requires image imports. I already know how to import an image using its path with pygame.image.import but it may be hard for the user to type or find the path of the image every time. so I have 2 options:
1- using a drag and drop system so that the user can drag the image from their desktop/ file explorer to the main window.
2- or the user can open the image themselves and my app would take a screenshot of it and import that. but i neither know how to take a screenshot using pygame nor how to take it when the window is minimized.
can someone guide me?
Related
This question already has an answer here:
how to use other fonts in pygame?
(1 answer)
Closed 9 months ago.
Specs:
MacOS Monterey, Python 3.10.4, Pygame 2.1.2
Context:
I'm trying to create a game using the Pygame module in Python. I want to display text on the screen and have figured that part out. What I'm not sure about is if I'm able to use custom fonts. By custom fonts I mean I've downloaded a font in the form of a .ttf file.
Question:
Is there any way to use this .ttf file/font in Pygame? I understand there are some built-in fonts like Comic Sans.
You can use a custom font with the following code:
font = pygame.font.Font(<font file>, <size>)
then render it using
font.render(<text>, True, <colour>)
See also https://nerdparadise.com/programming/pygame/part5
and https://www.pygame.org/docs/ref/font.html
This question already has answers here:
Can I detect if a window is partly hidden?
(2 answers)
How to determine if any part of the window is visible to Screen?
(1 answer)
How to get only the visible part of a window (Windows, gdi32, user32, etc)
(2 answers)
Closed 8 months ago.
I want to get a window's clip box so I can detect if the whole window is displayed.
package: win32gui
I know that IsWindowVisible() from the Windows API will return true if a window is NOT minimized, but it won't detect if the window is hidden behind other windows.
I also know that in C++, I could use GetWindowDC(); GetClipBox(); ReleaseDC(); to get a RECT struct with the coordinates of the smallest bounding rectangle of the window (I got this from another post on StackOverflow, but I haven't tested it).
In Python, I can use:
# That just returns a window by the title
handle = getWindowByTitle("Skype") # "Skype" is just an example
winDC = win32gui.GetWindowDC(handle)
# this function doesn't seem to exist/be implemented in win32gui
win32gui.GetClipBox(winDC, '''This also needs a RECT struct''')
win32gui.ReleaseDC(winDC)
How can I use GetClipBox() in Python? Or, is there any other way to check it?
I would like to not use any other package, because I want my app to have as few dependencies as possible.
I have also heard of ctypes, but I have never used them. I am not sure how it works, and/or if it can help here.
This question already has answers here:
Detect OS dark mode in Python
(5 answers)
Closed 1 year ago.
So I made an app, and it uses Tkinter for the UI. I am trying to make the app more user-friendly by allowing dynamic color modes. But I couldn't find a solution anywhere else. The plan is to fetch the current color mode and use it to decide window.configure(bg=light/dark) while window=Tk(). Any suggestions? :D
There is a module called darkdetect which can do this for you, darkdetect.theme() will return what theme your pc is using, hope this helps!
This question already has answers here:
How do I change the pygame icon?
(6 answers)
Closed 3 years ago.
I am making use of pygame module to make games but how do I change the default icon that appears on the Title Bar.
I am using Python 3.4.
To set the icon, you first need to load the image.
icon = pygame.image.load('image.png')
Next you use the image which you loaded, and set it as the icon.
pygame.display.set_icon(icon)
Have you tried set_icon()? Never used pygame before but it seems the way to go.
This question already has answers here:
Tkinter error: Couldn't recognize data in image file
(11 answers)
Closed yesterday.
I have the following problem. I generate .GIF files using an external application.
To me the GIFs look fine, I can open them without problems.
However, using
photo = PhotoImage(file=screenshot_file)
self.previewImageLabel.config(image=photo)
self.previewImageLabel.image = photo
to add an image to a Tkinter Label, is giving me the following error:
TclError: couldn't recognize data in image file "C:\Users\D8W\Python\hoang\combi
ne_model_neu\test_bauteile\SQTR-VO\prev_F45_SQTR.GIF"
The thing is, when I upload one of the GIFs to some online Converter and convert them to "GIF", they get displayed perfectly fine.
So my external application, which generates the GIFs, is putting something in there that Tkinter doesn't like.
How can I modify the GIFs to work? What are alternatives solving this problem?
I may not use modules that are not included in Python(like PIL).
Do you have any ideas?
Thanks in advance
I solved it, the problem was within my external application. I specified the file as .GIF but I have set the type to PNG.
Thanks anyway