How to make PyQt App give up window focus? - python

I have a python command line script that starts a PyQt Application showing the input of the video device in a little window. Then it starts a curses screen so that the user can control the camera with the keyboard.
After starting the script, the window focus is automatically on the PyQt window. Is there any way to tell PyQt to give up the window focus or curses / the terminal to reclaim it?
I use Linux (Mint Cinnamon) and the solution does not have to be OS independent.

You can try with setFocusPolicy here is the documentation. http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#setFocusPolicy

Related

How to open a Pygame window and a Tkinter window simultaneously?

I'm making a simple game using the Pygame Module. I require a Tkinter window to be open alongside the Pygame window.
Whenever I try to open both the windows, the second window only opens after I kill the first one.
Now, the only solution I can think of, is using multi-threading. But, I'm not able to implement it.
How do I go about this?
I would really appreciate some help here.
Thank You!
There is a fundamental design issue in pygame that makes it unable to open a window if the process already has a window. It will also prevent other windows from opening while it is running. However, you can open as many TK windows as you like and you can embed a pygame window inside a SDL drawing frame inside a TK window.
See this answer on how to use the drawing frame: Embedding a Pygame window into a Tkinter or WxPython frame
See this answer on how to create multiple windows in tkinter: How to open multiple windows in Tkinter

How to keep Tkinter window always on desktop

I use python 3.6 on windows 10. I want the tkinter window stay always on desktop even the desktop button is pressed. When I set topmost to true it stays always on desktop but it also precedes other windows. I want my window stays always on desktop without being the topmost of open windows.
Is there a way doing this?
Thanks.

Focus on pygame window

I am using
import ctypes
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6 )
to close the console and leave the pygame window open however I have to click on the window to interact with it. Can I make it so it goes back to the pygame window automatically?
A python script may be run in windowed mode by launching with pythonw, this may be automatically handled by changing the file extension to .pyw.
See this answer for more detailed information.

pyqt how to make application truly active

Under OS X, using the zetcode example for menubar, if one runs this from the command line:
$ python menubar.py
the application starts, but at the bottom of the window stack. This can be fixed by adding
self.raise_()
to the code.
However, the application is still not immediately active. The terminal application menubar still shows, not the pyqt menubar.
The only way to get the pyqt menubar to show is to switch away from the pyqt application or terminal application and back again.
Is this expected behavior? Is there anyway to fix this so the pyqt application immediately becomes active, i.e. the pyqt menubar immediately shows upon execution.
Versions: OS X 10.9, Qt 4.8.6, PyQt 4.11.3, SIP 4.16.5, python 2.7.8
The identical problem affects some apps bundled by PyInstaller. The following blog post discusses the fix, however the fix is in terms of the PyInstaller boot loader, which would not be directly relevant to your code, but it might be informative.
http://dvitonis.net/blog/2015/01/07/menu-bar-not-visible-when-building-pyqt-app-bundle-pyinstaller-mac-osx-mavericks-yosemite/
The problem relates to use of TransformProcessType() which is discussed in this linked article:
http://www.sheepsystems.com/developers_blog/TPT-show-menu.html
I do not know what Qt method would relate to the Mac OS TransformProcessType() but you might experiment with calling QWidget.setWindowState() in your mainwindow's __init__().
I was experiencing this behavior, but only when I launch with a --nosplash option to skip the splash screen in my application.
That gave me a hint, and I developed this workaround using a 'dummy' splash screen:
widget = QtGui.QMainWindow() # or whatever your main window class is
dummy = QtGui.QSplashScreen()
dummy.show()
dummy.finish(widget)
widget.show()
widget.raise_()

build cmd into Tkinter window

Hi i was wondering if you could have the comand prompt box pop into the Tkinter window when you start the program? Some thing like:
from Tkinter import *
admin = Tk()
cmd = Cmd(admin)
cmd.pack()
admin.mainloop()
I'm on windows
http://tkinter.unpythonic.net/wiki/CmdTkHere is what you want, this is not just opening a cmd window. its embedding cmd.exe into a Tkinter.Frame. And a note here if you rename the python script to ".pyw" extension, the console will be hidden. Except for in a virtual environment's.
I don't believe there is any built in console widget. It may be possible to whip up a custom one using the Tkinter Text widget. However, that would take a bit of effort/time.
Another possible option is simply have your program launch command prompt.
Two different ways to launch command prompt on a Windows machine.
import subprocess, os
subprocess.Popen('cmd.exe')
os.system("cmd.exe")
EDIT:
Unforunetly I don't believe there is any built in widget like that. However I thought of another possible solution, check out the code for the IDLE GUI, it has a console and the GUI portion is entirley written using Tkinter. So you may be able to utelize that code.

Categories