What I want to pop-up is minimized at taskbar.
But when I run below code, not minimized program pop-up, one more program run, and it cannot be clicked or seen and simply exists in the taskbar.
import win32gui, win32con
hwnd = win32gui.FindWindow(None, "League of Legends")
win32gui.SetForegroundWindow(hwnd)
win32gui.ShowWindow(hwnd, win32con.SW_SHOW)
What I expected : minimized program pop-up
Firstly make sure that you are locating the right window using this Finder tool. If you do not have Visual Studio, you can also download Winspector
Next, what you can try is to swap the arguments, for e.g
hwnd = win32gui.FindWindow("League of Legends", None)
Arguments for .FindWindow is className followed by windowName which can be found here
Moreover, you can set specific flags for your window to show.
For example if the initial state is minimized, you can show it by using the SW_SHOWNORMAL flag. Usage is as such,
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
(SW_SHOW) Activates the window and displays it in its current size and position.
(SW_SHOWNORMAL) Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
Related
This code is used to hide or dock the current window, and then create a new window using CTkTopLevel, and then to automatically undock or bring back the previous window to the screen. This seems to work on OSX perfectly, but when I try it on my Fedora machine, it fails to undock? Any reason why?
This is the code, called in both machines.
def CreateNewAccount(self):
#hide the previous window // seems to only work on OSX well
self.iconify()
#create new window
window = customtkinter.CTkToplevel(self)
window.title("Project")
window.geometry("1200x800")
window.resizable(False, False)
window.protocol("WM_DELETE_WINDOW", self.deiconify())
It should automatically undock and dock when deleting the window, tried other things like withdraw and it didn't work. Sometimes got a bug where after deleting the second tab, it would stay there as an unreactive tab and would only disappear after I closed the whole program.
I'm making a GUI using pyqt5 and I have two windows. In the first window, there is a button to open the second window. Now, I want to prevent windows switching from the second window to the first one. For example, when we open file dialog, we cannot switch to the main window and the main window is not clickable. (you can check it)
I have tried to set windows flag with :
setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
but it just makes the second window stay on top and I can still switch to the first window. Is there a way to prevent windows switching or make the first window to be not clickable?
Thanks in advance
You can make the window modal by:
setWindowModality(Qt.ApplicationModal)
I am working on a project written in Python that should perform some actions in an opened application window. For example I run application window with 3 buttons at 3 different positions. I write a script using auto-gui lib for python 3 and set x, y coordinates to click on 3 button positions. But my problem is: If I minimize this window, clicker clicks at the given position within another currently open window.
My main question: is there a way (with help of a lib or by any other means) to trigger or bind this script to work only with this opened (or specified) application. And if I minimize this window, clicker continues to work in this minimized window, not in the currently active one. Please suggest.
You should have a look at win32gui module, more specifically to SetActiveWindows, SetForegroundWindow, SetActiveWindows also EnumWindows to find your application.
With these you can detect a certain application by it's title using EnumWindows you can then maximize it and set it as active so it will be fullscreen and the first one you see on the monitor. This way you can now use the (x,y) coordinates for clicks because the windows will always be maximized therefore the buttons in the same position everytime.
When I make a pygame window (I believe it uses SDL), it launches as a popup window, as I want, since then it doesn't affect the layout or visibility of elements. But if I launch a simple program using GTK and Cairo, it doesn't launch as a popup. Is there some specific env flag, signal, etc. that needs to be used to launch a window as a popup rather than a tiled window?
pygame hello world code
cairo+gtk code, GTK Window section, past mid point of page
To do this in GTK, you need to call
gtk_window_set_type_hint((GtkWindow*)windowname, GDK_WINDOW_TYPE_HINT_DIALOG);
https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-type-hint
i3 will take window hints, and if a window tells i3 it is a dialog window, it will make it float automatically.
Get the WM_CLASS class or instance for the window with xprop and set floating enable for the window.
For example I have this in my i3 config
for_window [instance="Game of Life"] floating enable
I have a statusItem application written in PyObjC. The statusItem has a menuItem which is supposed to launch a new window when it is clicked:
# Create statusItem
statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
statusItem.setHighlightMode_(TRUE)
statusItem.setEnabled_(TRUE)
statusItem.retain()
# Create menuItem
menu = NSMenu.alloc().init()
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Preferences', 'launchPreferences:', '')
menu.addItem_(menuitem)
statusItem.setMenu_(menu)
The launchPreferences: method is:
def launchPreferences_(self, notification):
preferences = Preferences.alloc().initWithWindowNibName_('Preferences')
preferences.showWindow_(self)
Preferences is an NSWindowController class:
class Preferences(NSWindowController):
When I run the application in XCode (Build & Go), this works fine. However, when I run the built .app file externally from XCode, the statusItem and menuItem appear as expected but when I click on the Preferences menuItem the window does not appear. I have verified that the launchPreferences code is running by checking console output.
Further, if I then double click the .app file again, the window appears but if I change the active window away by clicking, for example, on a Finder window, the preferences window disappears. This seems to me to be something to do with the active window.
Update 1
I have tried these two answers but neither work. If I add in to the launchPreferences method:
preferences.makeKeyAndOrderFront_()
or
preferences.setLevel_(NSNormalWindowLevel)
then I just get an error:
'Preferences' object has no attribute
You need to send the application an activateIgnoringOtherApps: message and then send the window makeKeyAndOrderFront:.
In Objective-C this would be:
[NSApp activateIgnoringOtherApps:YES];
[[self window] makeKeyAndOrderFront:self];
I have no idea of PyObjC, never used that, but if this was Objective-C code, I'd say you should call makeKeyAndOrderFront: on the window object if you want it to become the very first front window. A newly created window needs to be neither key, nor front, unless you make it either or like in this case, both.
The other issue that worries me is that you say the window goes away (gets invisible) when it's not active anymore. This sounds like your window is no real window. Have you accidentally set it to be a "Utility Window" in Interface Builder? Could you try to manually set the window level, using setLevel: to NSNormalWindowLevel before the window is displayed on screen for the first time whether it still goes away when becoming inactive?