Difference in behavior of transparent Frame made with tkinter in pyinstaller [Python]

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).

environment

Windows10-64bit Python3.7 Pyinstaller 3.6

What is pyinstaller

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.

Difference in behavior

(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.

Sample code

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.

Execution result

compare.gif (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. pytoninstallerjkpy.gif

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. pytonjkpy.gif

Summary

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

Difference in behavior of transparent Frame made with tkinter in pyinstaller [Python]
Create a frame with transparent background with tkinter [Python]
I made a simple typing game with tkinter in Python
Tank game made with python About the behavior of tanks
I made a puzzle game (like) with Tkinter in Python
Numer0n with items made in Python
Check the behavior of destructor in Python
GUI image cropping tool made with Python + Tkinter
[Python] I made a Youtube Downloader with Tkinter.
How to use tkinter with python in pyenv
About the behavior of Model.get_or_create () of peewee in Python
Project Euler # 6 "Difference in sum of squares" in Python
Basics of I / O screen using tkinter in python3
Coordinates of the right end of Label made with tkinter
[python] behavior of argmax
Difference between Ruby and Python in terms of variables
[python] Calculation of months and years of difference in datetime
An introduction to cross-platform GUI software made with Python / Tkinter! (And many Try and Error)! (In the middle of writing)
Try scraping the data of COVID-19 in Tokyo with Python
Allow brew install of command line tools made in Python
Python module num2words Difference in behavior between English and Russian
Calculate the square root of 2 in millions of digits with python
[For beginners] Summary of standard input in Python (with explanation)
[Homology] Count the number of holes in data with Python
Comparison of data frame handling in Python (pandas), R, Pig
Scraping with selenium in Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Find the difference in Python
Debugging with pdb in Python
I made blackjack with python!
Working with sounds in Python
Scraping with Selenium in Python
Equivalence of objects in Python
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
Run Label with tkinter [Python]
Implementation of quicksort in Python
I made blackjack with Python.
Othello made with python (GUI-like)
I made wordcloud with Python.
Life game with Python [I made it] (on the terminal & Tkinter)
Made it possible to convert PNG to JPG with Pillow of Python
I couldn't use tkinter with python installed by pyenv of anyenv
IPynb scoring system made with TA of Introduction to Programming (Python)
Output the contents of ~ .xlsx in the folder to HTML with Python
I made a lot of files for RDP connection with Python
Visualize the frequency of word occurrences in sentences with Word Cloud. [Python]
Python script written in PyTorch is converted to exe with PyInstaller
Get a list of files in a folder with python without a path
Number recognition in images with Python
Pixel manipulation of images in Python
[Python] Show multiple windows in Tkinter
Testing with random numbers in Python
SNS Python basics made with Flask
Difference between list () and [] in Python
Difference between == and is in python
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
Behavior when listing in Python heapq