opencv window in tkinter frame - python

I am making a hand controlled media player application in Python and through OpenCV.I want to embed gesture window of OpenCV in Tkinter frame so I can add further attributes to it.
Can someone tell how to embed OpenCV camera window into Tkinter frame?

OpenCV window in Tkinter window is not good idea. Both windows use own mainloop (event loop) which can't work at the same time (or you have to use threading) and don't have contact one with other.
Probably it is easier to get video frame and display in Tkinter window on Label or Canvas. You can use tk.after(miliseconds, function_name) to run periodically function which will update video frame in Tkinter window.

Related

How to put a pygame in a tkinter application?

I programmed a board game in pygame, which is cool and all but I'd like to put it in a tkinter window so that I have space above my game, in which I can put buttons for resetting the board, etc.
How do I embed this? I would like to only have a tkinter window and not a seperate pygame window.
I made a window using
win = pygame.display.set_mode((WIDTH, HEIGHT)
pygame.display.set_caption('Game')
And then I displayed it using a while loop with
pygame.display.update()
I genuinely don't know how to make a tkinter that embeds this.
I tried using this solution, however when I ran this program I got two windows, which isn't what I want
This is complicated.
Both toolkits have their own windowing subsystems.
I remember once coming across a way to have Pygame's SDL render into a canvas in another window - but I can't now recall if that was X11 (~Linux) specific.
You will jabe to either have your buttons and controls rendered by Pygame - in that case there are complementary libraries such as Phil's Pygame Utilities ("PGU" - I have republished a version of it for Python3 https://pypi.org/project/pygame-pgu/ ) or another similar library.
Another option is to have your game application use 2 independent, related windows - in this case, running tkinter in a separate thread should be enough to have both working - or calling the .update() method on the root tkinter object in the pygame mainloop should suffice.

How do I create a window like that of CleanMyMac X in tkinter where some parts of the screen are outside the window?

CleanMyMacX image
As you can see, some of the buttons are outside of the window, and the window's title isn't visible. I am wondering if this is possible to do in python tkinter, and if so, how to do it.
Thanks!

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.

can Python Tkinter widget show a thread?

Is there a widget that shows a thread visually for Tkinter?
reason why. I want to open a Vpython window inside a Tkinter window.
I know there is a possibility to open a Vpython thread on the side while Tkinter is active, but can i show it inside Tkinter? (Like in some sort of Frame)
No, there is no widget to do that.

Tkinter - Keep application visible after lose focus

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?

Categories