Open In App

How to add a border color to a button in Tkinter?

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

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:

  1. A frame is a container for widgets. In this article, we are using frame widget parameters as highlightbackground and highlightthickness for adding border color to the button.
  2. Using Label widget to add text in GUI(graphical User Interface) with text font as a parameter.
  3. The Entry widget is used to take single-line input from the user.
  4. A frame with a thickness of 2 and a highlight background color as black is used for the button.
  5. Button widget with text as “Submit”, button background color as yellow with foreground color for text on the button is used as black in this GUI.
  6. Finally, a button with black border color with text as Submit is created successfully.

Below is the implementation:

Python3




import tkinter as tk
  
root = tk.Tk()
root.geometry('250x150')
root.title("Button Border")
  
# Label
l = tk.Label(root, text = "Enter your Roll No. :",
             font = (("Times New Roman"), 15))
l.pack()
  
# Entry Widget
tk.Entry(root).pack()
  
# for space between widgets
tk.Label(root, text=" ").pack()
  
# Frame for button border with black border color
button_border = tk.Frame(root, highlightbackground = "black"
                         highlightthickness = 2, bd=0)
bttn = tk.Button(button_border, text = 'Submit', fg = 'black',
                 bg = 'yellow',font = (("Times New Roman"),15))
bttn.pack()
button_border.pack()
  
root.mainloop()


Output:

Example 2: Using LabelFrame to add border color to a button.

Steps:

  1. A LabelFrame widget in tkinter contains the functionality of both label and a frame.
  2. The parameters of LabelFrame i.e., bd (border width) are taken as 6 with bg (background) color as black.
  3. The button widget is used for creating a button, the text parameter is used for adding text on button, and the button background color is taken as green with black color text on it.
  4. Finally, a button with black border color using LabelFrame widget with text as ‘Button’ on it is created successfully.

Below is the implementation:

Python3




from tkinter import *
  
window = Tk()
window.geometry('250x150')
window.title('Button Widget')
  
# Button with black border
border = LabelFrame(window, bd = 6, bg = "black")
border.pack(pady = 10)
  
btn = Button(border, text="Button", width = 8,
             bg = "#6CD300", fg = "black")
btn.pack()
  
window.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 Change Tkinter LableFrame Border Color?
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 Im
3 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
Python | Add style to tkinter button
Tkinter is a Python standard library that is used to create GUI (Graphical User Interface) applications. It is one of the most commonly used packages of Python. Tkinter supports both traditional and modern graphics support with the help of Tk themed widgets. All the widgets that Tkinter also has available in tkinter.ttk.Adding style in a tkinter.tt
4 min read
Python | Add image on a Tkinter button
Tkinter is a Python module which is used to create GUI (Graphical User Interface) applications with the help of varieties of widgets and functions. Like any other GUI module it also supports images i.e you can use images in the application to make it more attractive. Image can be added with the help of PhotoImage() method. This is a Tkinter method
3 min read
PyQt5 QSpinBox - Add border to the down button
In this article we will see how we can add border to the down button of spin box. Spin box consist of two buttons up and down, down button is used to decrement the value, it has its own default border although we can change it. Below is how down button with customized border looks like. ; In order to do this we have to change the style sheet code a
2 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
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. ApproachImport moduleCreate a windowSet a label widget with required attributes for borderPlace this widget on the window created Syntax: Labe
2 min read
Hide Python Tkinter Text widget border
Tkinter is a standard GUI library for Python, providing tools to create graphical user interfaces easily. When designing interfaces, developers often encounter the need to customize widget appearances, including removing widget borders. Borders can sometimes clash with the desired aesthetic or layout of the application. This article explores what w
3 min read
How to check which Button was clicked in Tkinter ?
Are you using various buttons in your app, and you are being confused about which button is being pressed? Don't know how to get rid of this solution!! Don't worry, just go through the article. In this article, we will explain in detail the procedure to know which button was pressed. Steps by Step Approach: Step 1: First, import the library Tkinter
3 min read
Practice Tags :
three90RightbarBannerImg