- 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 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.
#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()
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.
- 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 disable Home and other system buttons in Android?
- How can I use multiple submit buttons in an HTML form?
- How can I put a Java arrays inside an array?
- Removing minimize/maximize buttons in Tkinter
- How to create Tkinter buttons in a Python for loop?
- How to check if two Strings are anagrams of each other using C#?
- How can I disable typing in a ttk.Combobox tkinter?
- How can I resize the root window in Tkinter?
- Can I find out the next auto_increment to be used?
- How to disable Home and other system buttons in Android using Kotlin?
- Check whether two strings are anagram of each other in Python
- C# program to determine if Two Words Are Anagrams of Each Other