Tkinter Button bd
Tkinter Button bd option sets width or stroke of the border around the outside of the button.
In this tutorial, we will learn how to use bd (border) option and change the width of the border for button.
Example 1 – Border bd Values
You can provide an integer that specifies the thickness or width of border in pixels.
Or you can use a string and specify in other dimensional units. The string should have a number followed the unit character presented in the following table.
Unit | Description |
c | Centimeters |
i | Inches |
m | Millimeters |
p | Printer’s points (about 1/72?) |
Following code snippet provides the possible border (bd) values with different dimensional units.
tkinter.Button(window_main, bd=5) #pixels
tkinter.Button(window_main, bd='0.1c') #centimeters
tkinter.Button(window_main, bd='0.1i') #inches
tkinter.Button(window_main, bd='2m') #millimeters
tkinter.Button(window_main, bd='2p') #points (printer)
Example 2 – Tkinter Button Border Width
In the following example, we will make a Tkinter application with a button. The button will have a border width of 10 pixels.
Python Program
import tkinter
window_main = tkinter.Tk(className='Tkinter - TutorialKart', )
window_main.geometry("400x200")
button_submit = tkinter.Button(window_main, text ="Submit", bd=10)
button_submit.config(width=20, height=2)
button_submit.pack()
window_main.mainloop()
Output
Conclusion
In this Python Tutorial, we learned about Tkinter Button option bd (border width) with the help of example Python programs.