Previously, I introduced how to make a frame with a transparent background in Create a frame with a transparent background with tkinter [Python]. This transparent frame, but with $ python hoge.py
(hereinafter referred to as $ python)
I will introduce the difference in behavior when the exe file with $ pyinstaller hoge.py --onefile
is executed (hereinafter referred to as $ pyinstaller).
Windows10-64bit Python3.7 Pyinstaller 3.6
A library that allows you to create an exe file for Windows by simply executing a simple command.
$pip install pyinstaller
Can be installed with. However, you need to check the Official Site to see if it corresponds to the version of python you are using.
I tried to execute it with Python 3.8 on a certain day in March 2020, but it was not supported, so I could not output the exe file successfully.
An exe file is created with $ pyinstaller hoge.py
, but if you add the --onefile
option, it will be combined into one exe file, which is convenient.
(Here, "click" refers to all left, middle, and right clicks unless otherwise specified.)
Basically, it looks the same, but if you use $ python
, click the transparent part and click the window under __Frame __.
On the other hand, if you use $ pyinstaller
, even if you click the transparent part, you can just click __the Frame and it will not interfere with the window below. __
The sample code and execution results are shown below.
from tkinter import ttk
import tkinter
def lclick(self):
print("lclick")
label=ttk.Label(master=root,font=("Meiryo",30),text="■ Don't get thinner ... ■",foreground="red",background="green")
label.bind("<1>",lclick)
label.place(x=0,y=150)
root=tkinter.Tk()
root.wm_attributes("-transparentcolor", "snow")
ttk.Style().configure("TP.TFrame", background="snow")
f=ttk.Frame(master=root,style="TP.TFrame",width="400",height="300")
f.pack()
label=ttk.Label(master=root,font=("Meiryo",30),text="■ Don't get thinner ...",foreground="red",background="snow")
label.bind("<1>",lclick)
label.place(x=0,y=150)
root.mainloop()
It is a program that makes the label's background green when the label is left-clicked.
(The left is the result of executing the exe file converted with $ python
and the right is $ pyinstaller
, and the code is the same for both)
This is a huge difference.
The example of Twitter search results are sent like a certain video site [python] is easy to understand.
This will run a label
with a transparent background
over the transparent window and for that label
label.bind ("<1>", leftClickFunction)
,label.bind ("<3>", rightClickFunction)
is a program that executes a function when clicked.
If you use $ pyinstaller
, the function when you click correctly is executed as shown in the GIF below.
On the other hand, if you use $ python
, you cannot click label
, so you cannot execute the function set in bind as shown below, and you can see that the back window is selected in blue by D & D.
In the above environment, if you click a transparent Frame in $ python hoge.py
, you will click the window below the Frame, so you will not be able to click the label
on the Frame. However, it may be solved by converting it to an exe, so I want to use it properly according to the purpose.
I couldn't click label
and it was crushed for n hours ()
Recommended Posts