2

Does anyone know why the ttk.Entry widget font is being overwritten when creating the widget outside of a function called by a Button but it retains the font correctly if you create the widget using a ttk.Button?

import tkinter as tk
from tkinter import ttk
import sv_ttk

def newEntry():
    entry = ttk.Entry(gui, font="Calibri 14 bold")
    entry.pack()

gui = tk.Tk()

sv_ttk.set_theme("dark")

entry = ttk.Entry(gui, font="Calibri 14 bold")
entry.pack()

button = ttk.Button(gui, text="New Entry", command=lambda: newEntry())
button.pack()

gui.mainloop()

I have tried using ttk.Styles() to add a style to the ttk.Entry widget and that does not work either.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
Michael
  • 23
  • 2
  • Author of sv-ttk here. With sv-ttk version 2.4.5 your code will work as expected. The theme no longer overwrites explicitly set fonts. – rdbende Apr 22 '23 at 11:40

1 Answers1

1

You should update your gui after setting the theme to dark:

import tkinter as tk
from tkinter import ttk
import sv_ttk

def newEntry():
    entry = ttk.Entry(gui, font="Calibri 14 bold")
    entry.pack()

gui = tk.Tk()

sv_ttk.set_theme("dark")
gui.update()

entry = ttk.Entry(gui, font="Calibri 14 bold")
entry.pack()

button = ttk.Button(gui, text="New Entry", command=lambda: newEntry())
button.pack()

gui.mainloop()
Tranbi
  • 11,407
  • 6
  • 16
  • 33
  • 1
    Huh. I could have sworn I tried that at one point in the last 4 hours of debugging this... Thank you!! :) – Michael Mar 10 '23 at 09:08