How do I change the border color of a tkinter widget?

浪子不回头ぞ 提交于 2020-06-05 11:35:02

问题


I've been trying to configure the border colour of a widget in Tkinter, and I was wondering how to do that....

I've checked on StackOverflow, and it says that I should use the configure option and then set highlightbackgroundcolor = {insert color here}. I've tried that and nothing has worked. Can someone please show me a working sample of code so I can figure it out?


回答1:


There is no way to change the border color of a widget, the border color is tied to the background color of the widget. Instead, you can turn off the border, and then use a frame widget where you can set the background color of the frame.

import tkinter as tk

root = tk.Tk()

label_border = tk.Frame(root, background="red")
label = tk.Label(label_border, text="This has a red border", bd=0)
label.pack(fill="both", expand=True, padx=1, pady=1 )

label_border.pack(padx=20, pady=20)

root.mainloop()


来源:https://stackoverflow.com/questions/59593020/how-do-i-change-the-border-color-of-a-tkinter-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!