无法为Tkinter Button的边框上色? [英] No way to color the border of a Tkinter Button?

查看:114
本文介绍了无法为Tkinter Button的边框上色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它与其他一些小部件一起使用,但不适用于按钮。

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主题:

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

不过,使用样式更改边框宽度.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 Button的边框上色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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