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.
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:
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?
This question already has an answer here:
PyGObject and glade send window to the front
(1 answer)
Closed 8 years ago.
I am currently building an application with python 2.7 with Gtk3+.
I want to open a window on top of another window. If the second window is visible, the parent one should not be clickable.
So the behaviour should be the same like opening a dialog window.
What is the best way to achieve this?
You need to use the property window.set_transient_for(parent_window)
This post may help you if you are using glade.
This question already has an answer here:
How do I add a label to wxWidgets wxBitmapButton?
(1 answer)
Closed 9 years ago.
How do I create a bitmap button with attached text label in wxpyython. I have not come across any such generic buttons till now. I believe I will have to create one myself. How do I do it?
Thanks in advance
Look at the wx.lib.buttons module for various flavors of generic buttons.
Also, in the 2.9 release series the stock button class (wx.Button) can have a bitmap + text label.