Reputation: 780
I have a GUI created with tkinter
that is transparent.
import tkinter as tkinter
class TransparentWindow(tkinter.Frame):
def __init__(self, master = None):
# Initialize the mainframe and declare the master
tkinter.Frame.__init__(self, master)
# Make the window transparent
transparent = self.set_transparent_color(
window = self.master,
color = "yellow"
)
self.master["bg"] = transparent
self.master.wm_attributes("-topmost", True)
def set_transparent_color(self, window, color):
"""
Mark a sacraficial color as transparent for a window.
"""
window.wm_attributes(
"-transparentcolor",
color
)
return color
# Create window
root_window = tkinter.Tk()
TransparentWindow(root_window)
root_window.mainloop()
When I run this as a .py
file, the window appears and stays above all other windows (due to the -topmost
attribute). This window can be "clicked through". That is to say that you can click inside the window, and interact with the immediate window behind it. The transparent window will lose focus, but remain above the other window.
Now, when this code is compiled into an executable via the pyinstaller
command: pyinstaller --onefile -w script_name.py
and that executable is run, the transparent window will not lose focus if you click inside of it.
Why would the same code when run as a .py
vs .exe
alter the behavior of focus like this? Is this a pyinstaller
thing, or do tkinter
GUIs necessarily behave differently for some reason?
Upvotes: 1
Views: 415
Reputation: 2096
The following has been fixed in version 4.2
with the commit 3c3228d
. The issue persists if icon
is set to NONE
, currently reported as a bug. This along with other issues that arise are likely to be fixed in the near future.
Use the following command to update pyinstaller
pip install --upgrade pyinstaller
Upvotes: 2