gpt4 book ai didi

python - 无法为 Tkinter 按钮的边框着色?

转载 作者:行者123 更新时间:2023-11-28 19:05:06 25 4
gpt4 key购买 nike

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

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

最佳答案

我正在使用 linux,当我运行你的代码时,我得到一个带有红色粗边框的按钮,所以看起来默认的 Windows 主题不支持 highlightthickness 而默认的 linux 主题支持.

screenshot

如果您想更改边框颜色,可以使用一些 ttk 主题,例如“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()

screenshot clam

但是,使用 style.configure('my.TButton', borderwidth=10) 更改边框宽度并没有像预期的那样增加红色边框的宽度。

关于python - 无法为 Tkinter 按钮的边框着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47956021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com