Tkinter Grid – Adding a Button

In this tutorial I am demonstrating how to add a button using Grid in Tkinter. Placing a basic button can be done with only 2 lines of code highlighted in the code block below. The first line that is highlighted simply defines the button, adds text to it, and attaches it to the ‘main’ window the second uses grid and places it in column 1 and row 1.

 

As you can see this places a button in row 1 column 1 of our grid. When you read the code for this you may think that you in order to move your button over to the right you can just change the number in ‘column=’ section of line 12 when placing the button. This will in fact change the column your button is located in and is required to move your widget around, but it will not move because you have not given any weight to empty cells. To get this to work properly check out This Post where I outline how to give cells in your grid a weight.

Be the first to comment

Leave a Reply

Your email address will not be published.


*