Tkfiledialog Asksaveasfile Text Color/font
I am using the asksaveasfile function from tkFileDialog to save files using a GUI I'm creating. I'd like to change the color of the font within the dialog saveas window. Scoured th
Solution 1:
Disclaimer: I am using Linux and I am not sure whether my answer fully applies to other platforms given that the filedialogs look quite different in Windows.
It is not possible to fully change the color of the font because part of it is hard coded in the tcl code.
The elements surrounding the file list are mostly ttk widgets which can be themed via a ttk.Style
so that they look like the rest of the ttk widgets of the app. The menus can be changed with option_add
.
However, the file list is not as customizable. Indeed, the filenames are set back to black when unselected so there is no way to change that behavior from python.
import tkinter as tk
from tkinter import filedialog
from tkinter import ttk
root = tk.Tk()
root.option_add('*foreground', 'red') # set all tk widgets' foreground to red
root.option_add('*activeForeground', 'red') # set all tk widgets' foreground to red
style = ttk.Style(root)
style.configure('TLabel', foreground='red')
style.configure('TEntry', foreground='red')
style.configure('TMenubutton', foreground='red')
style.configure('TButton', foreground='red')
filedialog.askopenfilename(master=root, filetypes=[('*', '*'), ('PNG', '*.png')])
root.mainloop()
Post a Comment for "Tkfiledialog Asksaveasfile Text Color/font"