简体   繁体   English

是否可以设置 tkinter 文本小部件的样式?

[英]Is it possible to style a tkinter Text widget?

I've been using the 'ttkthemes' module to add some additional user-selectable themes to my application via an OptionMenu, and all my Text widgets stand out a bit in their standard style.我一直在使用 'ttkthemes' 模块通过 OptionMenu 向我的应用程序添加一些额外的用户可选主题,并且我所有的 Text 小部件都以其标准风格脱颖而出。

I would like to know if it is at all possible to style a Tkinter Text widget with ttk themes.我想知道是否可以使用 ttk 主题设置 Tkinter 文本小部件的样式。
I know you can't actually style the standard Tkinter widget (you instead must use the respective ttk version).我知道您实际上无法设置标准 Tkinter 小部件的样式(您必须使用相应的 ttk 版本)。
My issue is that there is no ttk.Text only the entry and I need multiple lines for a text editor.我的问题是没有 ttk.Text 只有条目,我需要多行文本编辑器。

One possibility would be to change background colour based on the selected theme, but this could be very long since there many themes to choose from.一种可能性是根据所选主题更改背景颜色,但这可能会很长,因为有很多主题可供选择。

Would anyone know of any possible way to get a stylable version of the Tkinter Text widget, so that it doesn't stand out as much?有谁知道任何可能的方法来获得 Tkinter 文本小部件的可样式化版本,以使其不那么突出?

Would anyone know of any possible way to get a stylable version of the Tkinter Text widget, so that it doesn't stand out as much?有谁知道任何可能的方法来获得 Tkinter 文本小部件的可样式化版本,以使其不那么突出?

You can create your own custom Text widget that listens to the <<ThemeChanged>> event, and then reconfigures itself based on the settings from the current theme or other widgets.您可以创建自己的自定义Text小部件来监听<<ThemeChanged>>事件,然后根据当前主题或其他小部件的设置重新配置自身。 For example, you could query the current theme to get the background color of an Entry widget and use that to set the background of the Text widget.例如,您可以查询当前主题以获取Entry小部件的背景颜色,并使用它来设置Text小部件的背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM