- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 can I put two buttons next to each other in Tkinter?
Tkinter generally provides three general ways to define the geometry of the widgets. They are − Place, Pack, and Grid Management. If we use the Pack geometry manager, then place the two buttons in the frame using side property. It places the buttons horizontally stacked in the window in (Left, Right, Top and Bottom) direction. The side property maintains the same width and internal padding between all the adjacent widget in the application.
Example
#Import the required Libraries from tkinter import * from tkinter import ttk import random #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter frame win.geometry("750x250") def clear(): entry.delete(0,END) def display_num(): for i in range(1): entry.insert(0, random.randint(5,20)) #Define an Entry widget entry= Entry(win, width= 40) entry.pack() #Create Buttons with proper position button1= ttk.Button(win, text= "Print", command=display_num) button1.pack(side= TOP) button2= ttk.Button(win, text= "Clear", command= clear) button2.pack(side=TOP) win.mainloop()
Output
Running the above code will display a window that contains two Buttons horizontally stacked adjacent to each other.
Now, click each button to see the resultant output.
- Related Articles
- How to place two divs next to each other in HTML?
- How to generate Tkinter Buttons dynamically?
- How do I position the buttons on a Tkinter window?
- How to create "next" and "previous" buttons with CSS?
- Can two acute angles be complement to each other?
- How to create Tkinter buttons in a Python for loop?
- How can I stock two arrow images (upvote/ downvote) on top of each other using CSS?
- Removing minimize/maximize buttons in Tkinter
- How can I use multiple submit buttons in an HTML form?
- Can two line segments intersect each other at two points?
- How to disable Home and other system buttons in Android?
- How can I resize the root window in Tkinter?
- How can I disable typing in a ttk.Combobox tkinter?
- How to put a border around a Frame in Python Tkinter?
- How to change the font and size of buttons and frame in tkinter?

Advertisements