How To Position Buttons In Tkinter

How to position buttons in tkinter

When a Python GUI application is designed with Tkinter, widgets (including buttons) require programming so that the underlying application logic can respond to mouse clicks and other actions. Additionally, in order for them to work as intended, widgets need to be positioned intuitively for the user.

Tkinter has three built-in layout managers that use geometric methods to position buttons in an application frame: pack, grid, and place

  • The pack manager organizes widgets in horizontal and vertical boxes that are limited to left, right, top, bottom positions offset from each other.
  • The grid manager locates widgets in a two dimensional grid using row and column relative coordinates.  
  • The place manager places widgets in a two dimensional grid using x and y absolute coordinates.

How to Position Buttons With Pack

Pack() has three options you can use: side, fill, expand.  

  • The side option aligns buttons horizontally.
  • The fill option aligns buttons vertically.
  • The expand option takes up the full height of the frame.

Read the detailed explanation on how to position button with pack() along with a video.


How to Position Buttons With Grid

Grid() is used to position buttons based on row and column coordinates on a grid in a frame similar to a spreadsheet.

  • The row option aligns button horizontally
  • The column option alights button vertically

Read the detailed explanation on how to position button with grid() along with a video.


How to Position Buttons With Place

Place() is used to position buttons based on x,y coordinates in a frame.

  • The x variable aligns button horizontally
  • The variable aligns button vertically

Read the detailed explanation on how to position button with place() along with a video.

Learn more about Tkinter and how to install it here.

If you want to take advantage of the latest version of Tkinter, you’ll need to install a version of Python that supports Tcl/Tk 8.5 or greater. This will provide you with the Ttk (Tile extension integrated into Tk), which is required in order to run the current Tk widget set.

Get Pre-compiled Python Packages For Data Science, Web Development, Machine Learning, Code Quality And Security

If you’re one of the many engineers using Python to build your algorithms, ActivePython is the right choice for your projects Get The Machine Learning Packages You Need – No Configuration Required. We’ve built the hard-to-build packages so you don’t have to waste time on configuration…get started right away! Learn more about ActivePython here.

Related Quick Reads:

What is Tkinter used for and how to install this Python Framework?

Flask vs Django: Comparing REST API Creation

ActivePython Sidebar Platform Graphic

Use ActivePython and accelerate your Python projects.

  • The #1 Python solution used by innovative enterprise teams
  • Comes pre-bundled with top Python packages
  • Spend less time resolving dependencies and more time on quality coding

Take a look at ActivePython

Remi M