python-3.x - 为什么连接样式时会出现两个窗口?
问题描述
在此处输入图像描述我有这样的代码:
from tkinter import Tk
import tkinter.ttk as ttk
"""Styles"""
style = ttk.Style()
style.configure('OrangeButton.TButton', foreground='white', background='#ff9203')
style.map('OrangeButton.TButton',
foreground=[('pressed', 'white'), ('active', 'white')],
background=[('pressed', '!disabled', '#adadad'), ('active', '#de8e26')])
root = Tk()
button = ttk.Button(root, text="Ok", width=20, style='OrangeButton.TButton')
button.pack(padx=50, pady=50)
root.mainloop()
我是新来的。我在互联网上搜索了解决方案,但找不到。他们到处写关于widthdraw()的文章,但这无济于事。始终出现两个窗口,并且自定义样式未应用于按钮。我究竟做错了什么?如何在 Google 上搜索此问题?请告诉我。谢谢。
解决方案
您只需要ttk.Style()
在root
窗口内定义。
from tkinter import Tk
import tkinter.ttk as ttk
root = Tk()
"""Styles"""
style = ttk.Style()
# add the these_use option and use the 'clam' theme
style.theme_use('clam')
style.configure('OrangeButton.TButton', foreground='white', background='#ff9203')
style.map('OrangeButton.TButton',
foreground=[('pressed', 'white'), ('active', 'white')],
background=[('pressed', '!disabled', '#adadad'), ('active', '#de8e26')])
button = ttk.Button(root, text="Ok", width=20, style='OrangeButton.TButton')
button.pack(padx=50, pady=50)
root.mainloop()
希望这能解决问题。
推荐阅读
- vba - 使用长数据类型时溢出错误 #6 VBA
- python - 从选择字段填充表单字段的最佳方式
- mysql - 返回字段的总计 - 按条件分组?
- jsoup - 我可以使用 JSoup、HtmlUnit 或其他任何东西获得最终的 HTML 页面(在执行脚本之后)吗?
- html - WebStorm HTML 在 Chrome 上运行
- c# - 挥之不去的Excel流程
- ruby-on-rails - Heroku 和 rails 卡在 pg_try_advisory_lock()
- android - 从 Android 中的字符串中提取
- matlab - 返回多个解决方案 GNU Octave 或 Matlab
- sql - Outlook vba 调用存储过程