Tkinter - Keep application visible after lose focus - python

I am trying to make a window still visible after it has lost focus. An example of what I'm trying to achieve is a window like the windows on-screen keyboard, when you click on another window, it doesn't go ontop of the on-screen keyboard window. Can anyone give me a way to do this in tkinter?

Related

Python Tkinter: Make popup window Modal Dialog?

I want to make a pop up window that requires the user to interact with before using the main window, Modal Dialog. For example, the messagebox requires the user to answer the question before moving on. If the user tries to click on the original window, the messagebox flashes and plays the iconic error sound. This is what I want; I would use a messagebox but I want to add buttons, labels, widgets, etc...
How do you make a pop up window Modal Dialog?

Python GTK 3 Popover off window?

So basically I have a window thats just a vertical list of buttons. I want to create a dropdown menu that goes off to the side without changing the size of the window. I am trying to do this with popover, but now I have the problem where my popover gets cut off by the window. Is there a way I can make it bleed past the window boundaries?
Popovers don't go wider than the parent window. You could have a try at a GtkMenu. They are allowed to go wider than the window, up to the width of the monitor.

Python capture events when console has focus with Tkinter

I'm building a console app, and would like to capture keystrokes in real time. The following code works perfectly until another window gets focus. From that point on, I'm not able to get back to a state where I can capture keystrokes and other events again with only the console visible.
import tkinter as tk
app = tk.Tk()
def handleKeypress(event):
key = event.char
if(key == 'q'):
app.destroy()
else:
print(key)
app.bind_all('<Key>', handleKeypress)
app.withdraw()
app.mainloop()
I've tried using various methods (grab and focus) to redirect the focus to my app. The best I was able to do was to get the Tkinter window visible and in focus with deiconify(), but I was not able to hide it again to make it as though the console is the only window.
Adding the following results in the Tkinter window appearing and disappearing repeatedly:
def lostFocus(event):
app.deiconify()
app.focus_force()
app.withdraw()
app.bind_all('<FocusOut>', lostFocus)
How can I go back to the state the application was in right after launch? Or even better, how can I force it to get all events without having to make the Tkinter window visible and in focus?
You can't do what you want. Tkinter is designed -- as are most GUI toolkits -- to only process events when it has the focus. That's the whole point of focus: for the OS to know where to send events.
The fact that it works initially is probably a bug in tkinter. Though, perhaps it can be explained by the fact that the window initially has focus, and when you withdraw the window the OS doesn't move the focus
The only way to restore focus is to make the window visible.

mouse button forward python

I'm currently trying to write an Image Viewer, but the "Forward/Backward" Buttons on the mouse are not triggering any of the possible binds in tkinter.
I tried the binds:
<Key>, <KeyPress>, <ButtonPress>, <Return>
but none of them can detect the mouse clicks on the forward/backward button.
Has Python even the possiblity to detect them?
Edit:
The buttons are called XButtons and are hookable with PyHook or PyQt, but if I try to let them run in the background, they are lagging massively, any way to prevent that?
I'm currently trying to let this script run smoothly in the background without causing extreme lags
Edit:
Using wxPython with PyHook solved my problem, since Tkinter and PyHook is causing huge lags, which don't appear with wxPython
The answer may vary by platform, and also by mouse driver.
On my OSX device where I have a logitech mouse with a total of five buttons, the fourth and fifth buttons are considered buttons 4 and 5. For example, I can bind to <Button-4> and <Button-5>.
That might work for you, or your mouse driver might assign those buttons to something else.

Tkinter application topmost, even over fullscreen

I'm using tkinter on Ubuntu.
I'd like my application to be on top of the screen, all the time. I'm aware of, and am currently using, wm_attributes("-topmost", 1). I've discovered that this is equal to right clicking on the menu bar of an application and selecting 'Always On Top', which works fine for most applications. However, this doesn't work when full-screen applications are launched (specifically, TF2). In such cases, my widget lies behind the game.
I'm also aware of overrideredirect(True), and this stays on top of the game even over full-screen, but this is not viable as the menu bar and being able to move the window are central to my application.
Is there a way to have tkinter remain on top of every application, including those that are full-screen? Basically the functionality of overrideredirect, but keeping the menu bar and the ability to move the window.

Categories