Let's say that I want to iconify
a tkinter window. I would use something like this:
from time import perf_counter
import tkinter as tk
def time(function, *args, **kwargs):
start = perf_counter()
function(*args, **kwargs)
return perf_counter() - start
root = tk.Tk()
root.update() # Make sure that the window appears on the screen
print(time(root.iconify)) # 2.0016179770000235
The problem is that it always takes a bit more than 2 seconds for the .iconify()
to run. Why is that? I looked at tkinter
's source code:
def wm_iconify(self):
"""Display widget as icon."""
return self.tk.call('wm', 'iconify', self._w)
iconify = wm_iconify
and it directly calls _tkinter
with the parameters. I tried reading _tkinter
's source code (here) but I can't find a trace for where the 2 seconds are going. My guess is that the problem is somewhere bellow _tkinter
.
Edit: This issue only effects Python 3.8.6
+ Ubuntu 20.10
but doesn't appear on Python 3.7.9
+ Window 10
.