tkFileDialog asksaveasfile 文本颜色/字体 [英] tkFileDialog asksaveasfile text color/font

查看:38
本文介绍了tkFileDialog asksaveasfile 文本颜色/字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tkFileDialog 中的 asksaveasfile 函数来使用我正在创建的 GUI 保存文件.我想在对话框另存为窗口中更改字体的颜色.搜索了互联网,我没有发现有人问同样的事情.

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 the internet and I haven't found anyone asking the same thing.

推荐答案

免责声明:我使用的是 Linux,但鉴于文件对话框看起来完全不同,我不确定我的回答是否完全适用于其他平台在 Windows 中.

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.

不可能完全改变字体的颜色,因为它的一部分是硬编码在 tcl 代码中的.

It is not possible to fully change the color of the font because part of it is hard coded in the tcl code.

文件列表周围的元素大多是 ttk 小部件,它们可以通过 ttk.Style 进行主题化,以便它们看起来像应用程序的其余 ttk 小部件.可以使用 option_add 更改菜单.但是,文件列表不是可定制的.实际上,文件名在未选择时会重新设置为黑色,因此无法从 Python 更改该行为.

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()

这篇关于tkFileDialog asksaveasfile 文本颜色/字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆