Reputation: 721
I need help with changing the border colour of a canvas in tkinter
This is my code:
w = int(root.winfo_screenwidth())
loader = Canvas(width=w, height=20, bd=1)
loader.grid(column=0, row=1)
I have tried:
fill="black"
outline="black"
bd="black"
Upvotes: 6
Views: 23185
Reputation:
tkinter Canvas allows TWO borders ( Python 3.9 tkinter.TkVersion
8.6 )
A 'normal' border and a highlight border. To change their color and thickness properties set the bd
, bg
, highlightthickness
and highlightbackground
named parameter:
obj_tkinter_Canvas = tkinter.Canvas( ...,
bd = 2
bg = 'white'
highlightthickness = 1,
highlightbackground = 'white'
)
The integers are border thicknesses in pixels. The background colors are set using symbolic names ( see for example https://www.tcl.tk/man/tcl8.4/TkCmd/colors.html for a list of available color names ).
Upvotes: 1
Reputation: 7735
You can use highlightbackground
option to change color of border highlight ring(which is also a border-like thing, but is separate from the actual border). (correction, thanks to Bryan Oakley's comment )
To change border highlight ring thickness, you should use highlightthickness
option.
loader = Canvas(..., highlightthickness=1, highlightbackground="black")
Also, if you want to remove that border highlight ring , you can set highlightthickness
to 0
.
loader = Canvas(..., highlightthickness=0)
Upvotes: 11