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.
Related
This question already has answers here:
In PyQt, what is the best way to share data between the main window and a thread
(1 answer)
Background thread with QThread in PyQt
(7 answers)
Example of the right way to use QThread in PyQt?
(3 answers)
Closed 3 months ago.
I wat to make an small python GUI in order to monitor the status of some services, to simplify it I want to see a green circle when the service is running and a red one when it is not
I have this piece of code to load a pixmap into a QLabel
self.m2w_state = QLabel(self)
running_icon = QPixmap('green.png')
self.m2w_state.setPixmap(running_icon)
self.m2w_state.resize(running_icon.width(), running_icon.height())
self.m2w_state.move(40, 50)
But now I'm trying to change this during execution from green to red. I tried in the same thread and the GUI got stuck, so I tried using a different thread, but an error appears saying that I cannot change the property from a different thread
How is the way to do that?
This question already has answers here:
Making the background move sideways in pygame
(2 answers)
How to scroll the background surface in PyGame?
(1 answer)
How to move the background image with keys in pygame?
(1 answer)
Closed 2 years ago.
I'm learning Python and trying to improve my skills by creating a little game using Pygame while learning through videos.
Therefore I would like to implements the basics menus, which include a pause menu and a couple more fonctions.
My goal is to have something like this:
Main Menu and level selection:
Game itself
Pause menu with restart/resume/back to main menu.
The problem is that, the more I use the pause menus and the more time passes, the more the main menu become visually glitched.
The visual glitch also don't seems to have a regular patter, sometimes it's the ship that stick, sometime the enemies or the lasers, or all of them at once.
The main title become also less and less clear with time.
I took some screenshots that you can find here.
I posted most of the useful code here so that you can try it.
The assets that I used can be download with this link if needed:https://techwithtim.net/wp-content/uploads/2020/04/assets.zip
EDIT:
It seems like the problem comes from this part of the code that manage the infinite auto-scrolling of the background image of the in-game loop.
global y
rel_y = y % BACKGROUND.get_rect().height
screen.blit(BACKGROUND, (0,rel_y - BACKGROUND.get_rect().height))
if rel_y < HEIGHT:
screen.blit(BACKGROUND, (0, rel_y))
y += 1
However, if the background is scrolling from the start in the main menu, it doesn't seems like there is any glitch anymore.
I don't really see why it glitched in the first place and I don't really know why making it loop from the start fixed the problem.
What could have made it happend?
(I edited the pastebin with the minimum needed for the code to work, it just need a background image that I can't add, but is on the asset download link if needed)
This question already has an answer here:
Cpp how to turn off specific monitor?
(1 answer)
Closed 5 years ago.
I'm looking for a way to programmatically power off multiple monitors.
Note: This doesn't mean power off ALL monitors.
The languages I'm currently able to compile in with my current enviorment is python/C/C++. I am aware of the easy C++ way of.
SendMessage(GetConsoleWindow(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);
However this powers off all the monitors the system has on, which isn't the result I'm after.
Let's say I have a Window with the name "Application Window", now I want to power off all of the monitors that does not have this app window open.
Note: Ideally it'd be implemented with python, however not needed.
Edit:
Found this, however I'm unable to recreate it and have the desired functionality.
Cpp how to turn off specific monitor?
Using ctypes you can access the winapi functions you mentioned:
import ctypes
WM_SYSCOMMAND = 0x0112
SC_MONITORPOWER = 0xF170
window = ctypes.windll.kernel32.GetConsoleWindow()
ctypes.windll.user32.SendMessageA(window, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
The msdn documentation:
SendMessage
GetConsoleWindow
WM_SYSCOMMAND
You should use GetDesktopWindow:
window = ctypes.windll.kernel32.GetDesktopWindow()
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 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.