No way to color the border of a Tkinter Button?(无法为 Tkinter 按钮的边框着色?)
问题描述
它适用于其他一些小部件,但不适用于按钮.
It works with some other widgets, but not with Buttons.
from Tkinter import *
root = Tk()
root.geometry("600x300+400+50")
btn_up = Button(root, text='Go UP')
btn_up.config(highlightbackground="red", highlightcolor="red", highlightthickness=10, relief=SOLID)
btn_up.pack()
root.mainloop()
Python 2.7 - Windows 10
Python 2.7 - Windows 10
推荐答案
我用的是linux,当我运行你的代码时,我得到一个带有粗红色边框的按钮,所以看起来默认的Windows主题不支持highlightthickness
而默认的 linux 主题会这样做.
I am using linux and when I run your code, I get a button with a thick red border, so it looks like that the default Windows theme does not support highlightthickness
while the default linux theme does.
如果你想改变边框颜色,可以使用一些 ttk 主题,比如 'clam':
If you want to change the border color, it is possible with some ttk themes like 'clam':
from Tkinter import *
import ttk
root = Tk()
style = ttk.Style(root)
style.theme_use('clam')
style.configure('my.TButton', bordercolor="red")
ttk_button = ttk.Button(root, text='Go UP', style='my.TButton')
ttk_button.pack()
root.mainloop()
但是,使用 style.configure('my.TButton', borderwidth=10)
更改边框宽度不会按预期增加红色边框的宽度.
However, changing the borderwidth, with style.configure('my.TButton', borderwidth=10)
does not increase the width of the red border as expected.
这篇关于无法为 Tkinter 按钮的边框着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法为 Tkinter 按钮的边框着色?


基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 筛选NumPy数组 2022-01-01