Tkinter doesn't associate a window with a pid

355 Views Asked by At

I'm using the wmctrl -lp to try and find the process id associated with a tkinter GUI window. However, it looks like the tkinter window is not associated with a pid.

0x06400010  0 0                     N/A tk

Using xprop, it looks like the _NET_WM_PID property is not set.

However, I can't find any way to get tkinter to set this automatically, or to set it explicitly from my python code.

The context is that I have a script that looks for any windows "owned" by a particular process, or any child processes thereof. But a tkinter window cannot be found by this script, because the script does not see it as being associated with the pid of the python script that creates the window.

Any help much appreciated.

EDIT: Further weirdness

It seems that this issue only arises if I run the python script from within a bash script.

So if I have a bash script gui_from_bash_script.sh which says:

#!/bin/bash

python my_gui.py

... and then I run ./gui_from_bash_script.sh, then I get the problem.

If I just run python my_gui.py from the terminal, I don't get the issue.

1

There are 1 best solutions below

0
samfrances On

I managed to resolve this by adding the following line when creating the root window.

root = tk.Tk()
root.client(socket.gethostname())   # THIS LINE HERE

I don't yet understand why this made the difference, but it appears to have done so.

wmctrl -lp now shows:

0x06400010  0 1234   my-host-name tk