Experimenting with the code

The best way to experience this piece of code is to make the following tweaks one by one, run the program, and resize the window to see the effect of each option.

As a first tweak, change the weights to 0:

 Grid.rowconfigure(root, x, weight=0)
Grid.columnconfigure(root, x, weight=0)

This will make the window non-responsive again.

Next, reassign the weights back to 1 and then comment out one of the two lines and see the difference. If you comment out the rowconfigure line the buttons will be responsive in the y direction, but non-responsive in the x direction and vice versa for columnconfigure.

Restore the program to its original state and then assign a different weight in each loop by changing the weight to x:

 Grid.rowconfigure(root, x, weight=x)
Grid.columnconfigure(root, x, weight=x)

So the first button will have a weight of 0, the second button will have a weight of 1, and so on. Now if you run the program and resize the window, the last button with weight=9 will be the most responsive (will take up the largest proportion of the available space), while the first button with a weight of 0 will be completely non-responsive (fixed size), as shown in the following screenshot:

As the last tweak, restore the program to its original state and change the value of the second argument to a fixed number, say 2:

 Grid.rowconfigure(root, 2, weight=1)
Grid.columnconfigure(root, 2, weight=1)

This will assign the weight only to the third button (counting starts with 0), so the third button becomes responsive, while the others stay non-responsive, as shown in the following screenshot:

As a matter of fact, in this last case since we are assigning weight only to a single widget, we could have as well assigned it outside the loop.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.140