Open In App

How to Change Tkinter LableFrame Border Color?

Last Updated : 01 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

LableFrame in Tkinter is the widget that creates the rectangular area which contains other widgets. In this article, we are going to see how we can change the border of the label frame. But for achieving the color, we need to go through the theme for Tkinter, hence we use ttk module for the same which is inbuilt in python 3 Tkinter.

Step by Step Implementation:

Step 1: Importing all the required modules

Python3




# import tkinter 
import tkinter as tk 
  
# import ttk theme module for styling
import tkinter.ttk as ttk


Step 2: Building the label frame and put some widgets inside it.

Python3




import tkinter as tk
import tkinter.ttk as ttk
  
# initialize the tkinter window
root = tk.Tk() 
  
# provide some width and height
root.geometry("300x300"
  
# created a label frame with title "Group"
labelframe = ttk.LabelFrame(root, text = "GFG")
  
# provide padding 
labelframe.pack(padx=30, pady=30
  
# created the text label inside the the labelframe
left = tk.Label(labelframe, text="Geeks for Geeks"
left.pack()
  
root.mainloop()


Output:

Example 1: Using Clam theme in Tkinter.

Clam is a theme for tkinter windows and widgets. It comes under ttk module. The syntax for creating clam ttk window:

style = ttk.Style()
style.theme_use('clam')

Note: We use a clam theme in ttk module which enables using properties like border colors. Other themes may not have properties like border color.

Below is the implementation: 

Python3




import tkinter as tk
import tkinter.ttk as ttk
  
root = tk.Tk()
  
# initialize style function
style = ttk.Style()
  
# Use clam theme
style.theme_use('clam')
  
# Used TLabelframe for styling labelframe widgets,
# and use red color for border
style.configure("TLabelframe", bordercolor="red")
  
labelframe = ttk.LabelFrame(root, text = "GFG")
labelframe.grid(padx = 30, pady = 30)
  
left = tk.Label(labelframe, text = "Geeks for Geeks")
left.pack()
  
root.mainloop()


Output:

Example 2: Building our own style functionality theme.

Syntax:

# creating the theme

style.theme_create(‘class_name’, # Name of the class                   

                   settings={         

                       ‘TLabelframe’: {  # Name of the widget 

                           ‘configure’: {  # Configure argument

                               ‘background’:’green’  # changing background argument

                           }

                       }

                     }

                   )

# For using the theme

style.theme_use(‘class_name’)

We created a style theme function with the help of ttk style. We use theme_create to create the functionality and can use that using theme_use for assigning the theme.

Below is the implementation: 

Python3




import tkinter as tk
import tkinter.ttk as ttk
  
# initialize the tkinter window
root = tk.Tk()
  
# initializing the style function
style = ttk.Style()
  
# creating the theme with the
# initializing the style function
style = ttk.Style()
  
# creating the theme with the
style.theme_create('style_class',
  
                   # getting the settings
                   settings={
  
                       # getting through the Labelframe
                       # widget
                       'TLabelframe': {
                           
                           # configure the changes
                           'configure': {
                               'background': 'green'
                           }
                       },
  
                       # getting through the Labelframe's 
                       # label widget
                       'TLabelframe.Label': {
                           'configure': {
                               'background': 'green'
                           }
                       }
                   }
                   )
style.theme_use('style_class')
  
# created a label frame with title "Group"
labelframe = ttk.LabelFrame(root, text="Group")
  
# provide padding
labelframe.pack(padx=30, pady=30)
  
# created the text label inside the the labelframe
left = tk.Label(labelframe, text="Geeks for Geeks")
  
left.pack()
  
root.mainloop()


Output:



Previous Article
Next Article

Similar Reads

How to change border color in Tkinter widget?
Prerequisites: Tkinter GUI, Tkinter Widgets Tkinter is Python’s standard GUI package which provides us with a variety of common GUI elements such as buttons, menus, and various kinds of entry fields and display areas which we can use to build out an interface. These elements are called Tkinter Widgets. Among all color options for a widget, there is
3 min read
How to add a border color to a button in Tkinter?
In this article, we will learn how to add border color to a button in Tkinter. In the first example, we are using the frame widget to add border color to a button in frame by highlighting the border with black color and a thickness of 2. Example 1: Using Frame widget to add border color to a button. Steps: A frame is a container for widgets. In thi
2 min read
Change color of button in Python - Tkinter
Prerequisite: Creating a button in tkinter, Python GUI – tkinter In this article, we are going to write a Python script to change the color of the button in Tkinter. It can be done with two methods: Using bg properties.Using activebackground properties. Example 1: using bg properties. We can change the button background color with bg properties, Th
1 min read
How to change background color of Tkinter OptionMenu widget?
Prerequisites: Tkinter While creating GUI applications, there occur various instances in which you need to make selections among various options available. For making such choices, the Option Menu widget was introduced. In this article, we will be discussing the procedure of changing menu background color of Tkinter’s option Menu widget. To achieve
2 min read
Change the color of certain words in the tkinter text widget
Python has various options for Graphical User Interface (GUI) development. One of the options is Tkinter. Tkinter and Python together provide a faster way for GUI development. The Tk GUI toolkit provides an object-oriented interface. For creating GUI applications using Tkinter we have to follow a few steps – Import Tkinter module.Create the main wi
3 min read
How to change the color and symbol of the cursor in Tkinter?
Tkinter is a standard GUI library for Python. It provides various widgets for GUI development. We can give background color to widgets as per choice. But, sometimes background color affects mouse pointer visibility. In such cases, changing the cursor color makes the mouse pointer distinguishable. The color of the cursor can be changed by specifying
2 min read
How To Change The Text Color Using Tkinter.Label
In Tkinter, we can customize the styling of elements such as labels to enhance the appearance of our GUI applications. One common customization is changing the text color of a Label widget. In this article, we will explore different approaches to changing the text color using tkinter.label in Python. Change The Text Color Using Tkinter.LabelBelow a
2 min read
Change The Color Of A Tkinter Label Programmatically
Tkinter is a module in Python which is used to create GUI applications. It has many useful widgets such as Label, Button, Radiobutton, Checkbutton, Listbox, and more. In this article, we will learn about changing the color of a Tkinter label widget in Python. Tkinter Label WidgetThe Label is one of the widgets in Tkinter. It is used to display text
4 min read
How To Change A Tkinter Window Background Color
Changing the background color of a Tkinter window is a common task for creating visually appealing GUI applications in Python. In this article, we will explore three different approaches to achieve this. Change a Tkinter Window Background ColorBelow are some of the ways by which we can change a Tkinter window background color using Python: Using th
2 min read
Change marker border color in Plotly - Python
In this article, we are going to discuss how to change marker border color using plotly module in Python. Plotly is definitely a must-know tool for visualization since it's incredibly powerful easily used and has the big benefit of interactivity we are able to export visualization, being able to run on browsers, build with DASH which is web-based p
4 min read
Practice Tags :
three90RightbarBannerImg