Here is some simplified code that highlight my problem:
import time
import tkinter as tk
from tkinter import font
class Example(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tic = time.perf_counter()
for i in range(40):
label = tk.Label(self, text = "testing this font", font = ("Courier", 18))
label.pack()
toc = time.perf_counter()
print(f"{toc-tic:0.4f} seconds")
if __name__ == "__main__":
root=tk.Tk()
example = Example(root)
example.pack(side="top", fill="both", expand=True)
root.mainloop()
When I run this it takes about 2 seconds, however, if I remove "font=('Courier', 18)" from the tk.Label, then it takes about 0.03 seconds to load. Is there a reason why not defining a font would allow the frame to render so much faster?
Thank you in advance,
-John