How to Set Border of Tkinter Label Widget?
The task here is to draft a python program using Tkinter module to set borders of a label widget. A Tkinter label Widget is an Area that displays text or images. We can update this text at any point in time.
- Import module
- Create a window
- Set a label widget with required attributes for border
- Place this widget on the window created
Syntax: Label ( master, option, … )
- Master: This represents the parent window.
- Option: There are so many options for labels like bg, fg, font, bd, etc
Now to set the border of the label we need to add two options to the label property:
- borderwidth: It will represent the size of the border around the label. By default, borderwidth is 2 pixels. “bd” can also be used as a shorthand for borderwidth.
- relief: It will Specify the look of a decorative border around the label. By default, it is FLAT. Other than Flat there are many more acceptable values like raised, ridge, solid, etc.
Given below is the implementation to set border and edit it as required.
Program 1: To set a border
Program 2: to set the border and edit it as required.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course