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

后端 未结 1 725
傲寒
傲寒 2020-12-07 06:36

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 sh

相关标签:
1条回答
  • 2020-12-07 06:59

    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()
    
    0 讨论(0)
提交回复
热议问题