Python is awesome

Python is a programming language, it can be used to make small automation scripts, as well as to generate web pages, and even to make complex graphical software.

Here are a few reasons, from my experience, why Python is awesome.

Python is simple

It is simple to learn, and it is simple to use. It borrows principles from “old school” languages that a lot of programmers are already used to work with. Anyone that already knows 2 or 3 other languages already knows most of the concepts that Python uses. But the language is also a good one to learn programming, because the syntax is easy to remember.

The code itself is very straight to the point, it doesn’t need an endless stream of brackets and weird symbols. Which is in big part due to the fact that blocks are defined by their indentation, and I think this is one of the most interesting features of Python.

We can do a lot in a short time

Because it is a high-level language, many things already come built-in with the language, and those things are rather short and simple to use. Which means that when you need to write a script, you don’t need much time to figure out how to do it. And if there is a bug along the way, you won’t spend the rest of the day trying to find and fix it.

The right tool for the right job

With most other languages, I have always felt like I was fighting against the language to make it do what I needed to do. Like if I was trying to unscrew a screw with a pair of pliers, it is possible to do it, although it is quite intricate. But with Python I can say that I “use” it and not that I “fight against” it. Python is the screwdriver for my screw. I finally found the programming language that seems to want me to succeed in my project as much as I want it myself.

The programming language that doesn’t get in your way

The greatest “feature” of the Python language, the fact that it isn’t an obstacle to the programmer. I’ve used many languages over the years, I can’t say that I became an expert with any of them yet but I worked with some long enough to use them with relative ease. But I haven’t managed to find one (except Python) that didn’t slow me down. Programming already requires quite a lot of work by itself, so it becomes really annoying when it ends up being a game of tricking the language in doing what we want. I feel like Python has been made with the programmer in mind, to ease our work, in contrary to most other languages which just seem to have been made to solve problems without any thoughts about the poor person that has to use it.

So this is why Python is awesome.

Tk Grid Form Resize

Most of the places that explain how Tk’s grid works will tell you the following:

(The examples are made with Python but should work with any language that supports Tk.)

Use “columnconfigure” and “rowconfigure” with a “weight” of at least 1 on each column and row inside the frame. So for a 2×2 grid:

myFrame.columnconfigure(0, weight=1)
myFrame.columnconfigure(1, weight=1)
myFrame.rowconfigure(0, weight=1)
myFrame.rowconfigure(1, weight=1)

Use the “sticky” option for every widget that needs to stick to at least one side of its container. So let’s say we put a button into each cell created above and make them stick to all four sides of their cell:

myButton1.grid(column=0, row=0, sticky=(N,S,E,W))
myButton2.grid(column=1, row=0, sticky=(N,S,E,W))
myButton3.grid(column=0, row=1, sticky=(N,S,E,W))
myButton4.grid(column=1, row=1, sticky=(N,S,E,W))

But even after doing this, which can take quite some time on large interfaces, it still doesn’t seem to work. The missing element, which no one seems to tell, is that the “root” container also has to be set to a weight greater than 0 with “columnconfigure” and “rowconfigure”. In this case we just need to do it for the cell (0,0) because the frame takes care of all other divisions of the window. So as it is suggested in various places, you probably have something like this in your main file:

root = Tk()
root.title("My application")

Which means that “root”, too, has to be configured by adding:

root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

And now, your widgets should stick to what you set them to.
Here’s the full code of the example:

#!/usr/bin/python

from tkinter import *
from tkinter import ttk

root = Tk()
root.title("My application")
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

frame = ttk.Frame(root)
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
frame.rowconfigure(0, weight=1)
frame.rowconfigure(1, weight=1)
frame.grid(column=0, row=0, sticky=(N,S,E,W))

button1 = ttk.Button(frame, text="Button1", command=lambda: print("Button1"))
button2 = ttk.Button(frame, text="Button2", command=lambda: print("Button2"))
button3 = ttk.Button(frame, text="Button3", command=lambda: print("Button3"))
button4 = ttk.Button(frame, text="Button4", command=lambda: print("Button4"))
button1.grid(column=0, row=0, sticky=(N,S,E,W))
button2.grid(column=1, row=0, sticky=(N,S,E,W))
button3.grid(column=0, row=1, sticky=(N,S,E,W))
button4.grid(column=1, row=1, sticky=(N,S,E,W))

root.mainloop()