Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border colours of canvases (tkinter)

Tags:

python

tkinter

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"
like image 905
curlpipesudobash Avatar asked Feb 15 '17 13:02

curlpipesudobash


People also ask

How to change the border color of a Tkinter widget?

These elements are called tkinter Widgets. Among all color options for a widget, there is no direct method to change the border color of the widget. As the border color of a widget is tied to the background color of the widget, it is impossible to set it individually.

How to add Tkinter border-color and highlightthickness using highlightbackground and highlightcolor?

Method 2: Using highlightbackground and highlightcolor 1 Import Tkinter module 2 Create a window 3 Create a widget with highlightthickness set to desired border thickness 4 Configure highlightbackground and highlightcolor attributes to the desired border-color 5 Place the widget on the window created More ...

What is labelframe widget In Tkinter?

A LabelFrame widget in tkinter contains the functionality of both label and a frame. The parameters of LabelFrame i.e., bd (border width) are taken as 6 with bg (background) color as black.

How to create a border variable with background color in WordPress?

Create a border variable with Frame widget with background color as its attributes We can also use a highlighted background and highlight color together to get a border color for our widget. We can even adjust the thickness of the border using the highlight thickness attribute. This method only works for some widgets like Entry, Scale, Text e.t.c.


2 Answers

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)
like image 115
Lafexlos Avatar answered Sep 24 '22 02:09

Lafexlos


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

like image 37
Claudio Avatar answered Sep 24 '22 02:09

Claudio