- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add padding to a tkinter widget only on one side?
Let us suppose that we want to add padding on one side (either top/bottom or left/right) of a particular widget. We can achieve this in Tkinter by using its pack() and grid() methods.
In pack() method, we have to define the value for “padx” and “pady”. On the other hand, the grid method requires only two tuples, i.e., x and y for adding padding around either of X-axis or Y-axis.
#import the required library from tkinter import * #Create an instance of window or frame win= Tk() win.geometry("700x400") #Create two buttons #Add padding in x and y axis b1= Button(win, text= "Button1", font=('Poppins bold', 15)) b1.pack(padx=10) b2= Button(win, text= "Button2", font=('Poppins bold', 15)) b2.pack(pady=50) b3= Button(win, text= "Button3", font= ('Poppins bold', 15)) b3.pack(padx=50, pady=50) #Keep running the window win.mainloop()
Running the above code will create a window containing three buttons that will have some padding around either of X, Y, or both axes.
- How to force Tkinter text widget to stay on one line?
- How to add a column to a Tkinter TreeView widget?
- Add advanced features to a tkinter Text widget
- How to make the Tkinter text widget read only?
- How to center a Tkinter widget?
- How to select only one Radiobutton in Tkinter?
- How to set focus on Entry widget in Tkinter?
- How to make a Tkinter widget invisible?
- How to update a Python/tkinter label widget?
- How to remove focus from a Tkinter widget?
- How to update a Button widget in Tkinter?
- How to Add One Side Left Border to TextView in Android using XML?
- How to clear Text widget content while clicking on the Entry widget itself in Tkinter?
- Change the focus from one Text widget to another in Tkinter
- Vertical and Horizontal Scrollbars on Tkinter Widget