import tkinter as tk
import tkinter.ttk as ttk
import tkinter.font as tk_font
window = tk.Tk()
window.title("Test")
window.geometry("800x600")
style = ttk.Style()
# ----------------------------------------------------------------------------------------
# Assign the first style
font_name = style.lookup("TLabelframe.Label", "font")
this_is_the_font_object: tk.font.Font = tk_font.nametofont(font_name).copy()
this_is_the_font_object.config(weight="bold")
style.configure("TLabelframe.Label", foreground="#0C529A", font=this_is_the_font_object)
print(this_is_the_font_object)
# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Assign the second style
font_name = style.lookup("TLabel", "font")
this_is_the_font_object: tk.font.Font = tk_font.nametofont(font_name).copy()
this_is_the_font_object.config(weight="bold")
style.configure("My.Bold.TLabel", font=this_is_the_font_object)
print(this_is_the_font_object)
# Why does this change the first style as well?
# ----------------------------------------------------------------------------------------
lf = ttk.LabelFrame(window, text="Frame Label:")
lf.pack()
ttk.Label(lf, text="Just a Label", style="My.Bold.TLabel").pack()
window.mainloop()
The "second style" block incorrectly affects the "first style" block despite being unrelated. If you comment out the second block, the font of the first block will change to the expected one. What's even more curious is that if you use a different python variable name in the second style (ie change this_is_the_font_object to foo in the second block only), the font won't be changed in the "first style". What's causing this? Is this a bug?
I am on Windows 10.