为什么tkinter GUI在作为.exe(通过pyinstaller创建)运行时表现不同?

为什么tkinter GUI在作为.exe(通过pyinstaller创建)运行时表现不同?,tkinter,focus,pyinstaller,Tkinter,Focus,Pyinstaller,我用透明的tkinter创建了一个GUI 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

我用透明的
tkinter
创建了一个GUI

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()
当我将其作为
.py
文件运行时,该窗口将出现并保持在所有其他窗口的上方(由于
-top
属性)。此窗口可以“点击通过”。也就是说,您可以在窗口内单击,并与它后面的直接窗口交互。透明窗口将失去焦点,但仍位于另一个窗口上方

现在,当此代码通过
pyinstaller
命令编译成可执行文件:
pyinstaller--onefile-w script_name.py
并运行该可执行文件时,如果在透明窗口内单击,则不会失去焦点


为什么相同的代码在作为
.py
vs
.exe
运行时会像这样改变焦点的行为?这是一个
pyinstaller
的东西,还是由于某种原因,GUI的行为必然会有所不同?

以下内容在
4.2版中通过提交得到了修复。如果
图标
设置为
,且当前报告为异常,则问题仍然存在。这一问题以及出现的其他问题很可能在不久的将来得到解决

使用以下命令更新
pyinstaller

pip install --upgrade pyinstaller

在w7 python 3.8下,如果没有pyinstaller,我也无法与后面的窗口交互。您使用的是哪个版本的
pyinstaller
?这似乎已在版本
4.2
中修复,请确保您有更新的版本,您可以执行
pip install--升级pyinstaller
,然后试用。@AST这解决了问题。经验教训:始终验证导入的模块是否为最新版本!非常感谢你。如果你回答这个问题,我会把它标为接受。