Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to get rid of widget border in Tkinter?
Tkinter widgets like Button, Entry, Frame, Label, and Canvas come with default borders that can sometimes interfere with your application's design. You can remove these borders using specific attributes to create cleaner, more customized interfaces.
Common Border Attributes
Different widgets use different attributes to control borders:
borderwidth or bd − Controls the width of the border (set to 0 to remove)
highlightthickness − Controls focus highlight border (Canvas, Entry)
relief − Controls the border style (flat, raised, sunken, etc.)
Example: Removing Borders from Multiple Widgets
Here's how to remove borders from Canvas, Entry, Label, and Button widgets ?
import tkinter as tk
# Create main window
root = tk.Tk()
root.geometry("700x400")
root.title("Widget Borders Example")
# Canvas with border
canvas_with_border = tk.Canvas(root, bd=2, highlightthickness=2, bg="lightblue")
canvas_with_border.pack(pady=5)
# Canvas without border
canvas_no_border = tk.Canvas(root, bd=0, highlightthickness=0, bg="lightgreen")
canvas_no_border.pack(pady=5)
# Entry with border
entry_with_border = tk.Entry(root, width=30, borderwidth=3)
entry_with_border.insert(0, "Entry with border")
entry_with_border.pack(pady=5)
# Entry without border
entry_no_border = tk.Entry(root, width=30, borderwidth=0, highlightthickness=0)
entry_no_border.insert(0, "Entry without border")
entry_no_border.pack(pady=5)
# Label with border
label_with_border = tk.Label(root, text="Label with border",
borderwidth=2, relief='solid')
label_with_border.pack(pady=5)
# Label without border
label_no_border = tk.Label(root, text="Label without border",
borderwidth=0)
label_no_border.pack(pady=5)
# Button with border
button_with_border = tk.Button(root, text="Button with border")
button_with_border.pack(pady=5)
# Button without border
button_no_border = tk.Button(root, text="Button without border",
borderwidth=0, highlightthickness=0)
button_no_border.pack(pady=5)
root.mainloop()
Widget-Specific Methods
Canvas Borders
For Canvas widgets, use both bd=0 and highlightthickness=0 ?
import tkinter as tk
root = tk.Tk()
root.geometry("300x200")
# Remove both border and highlight
canvas = tk.Canvas(root, bd=0, highlightthickness=0, bg="white")
canvas.pack(fill="both", expand=True)
root.mainloop()
Entry Field Borders
Entry widgets need both borderwidth=0 and highlightthickness=0 ?
import tkinter as tk
root = tk.Tk()
root.geometry("300x100")
entry = tk.Entry(root, borderwidth=0, highlightthickness=0,
relief="flat", bg="lightgray")
entry.insert(0, "Borderless entry")
entry.pack(pady=20)
root.mainloop()
Button Borders
For buttons, combine borderwidth=0 with relief="flat" ?
import tkinter as tk
root = tk.Tk()
root.geometry("200x100")
button = tk.Button(root, text="Flat Button",
borderwidth=0, relief="flat",
highlightthickness=0, bg="lightblue")
button.pack(pady=20)
root.mainloop()
Complete Border Removal
| Widget | Attributes to Set | Example |
|---|---|---|
| Canvas | bd=0, highlightthickness=0 |
Canvas(root, bd=0, highlightthickness=0) |
| Entry | borderwidth=0, highlightthickness=0 |
Entry(root, borderwidth=0, highlightthickness=0) |
| Button | borderwidth=0, relief="flat" |
Button(root, borderwidth=0, relief="flat") |
| Label | borderwidth=0 |
Label(root, borderwidth=0) |
Conclusion
Remove widget borders by setting borderwidth=0 and highlightthickness=0 where applicable. Use relief="flat" for buttons to achieve a completely flat appearance. This creates cleaner, more modern-looking interfaces.
