condensing/reducing vertical spacing between widgets in tkinter (Python) (AKA: setting vertical line/text spacing/padding)
<p>Here's my program:</p>

<pre><code>import tkinter as tk 

#Create main window object 
root = tk.Tk()

#build GUI
for i in range(5):
    tk.Label(root, text="hello", height=0).grid(row=i)

#mainloop
root.mainloop()
</code></pre>

<p>It produces the following (running in Xubuntu 16.04 LTS)</p>

<p><a href="http://i.stack.imgur.com/UmTmH.png" rel="nofollow"><img src="http://i.stack.imgur.com/UmTmH.png" alt="enter image description here"></a></p>

<p>Notice all that extra vertical space between the lines of text. I don't want that! How do I decrease it?</p>

<p>If I run this code instead:</p>

<pre><code>import tkinter as tk 

#Create main window object 
root = tk.Tk()

#build GUI
for i in range(5):
    tk.Label(root, text="hello", height=0).grid(row=i)
    tk.Grid.rowconfigure(root, i, weight=1) #allow vertical compression/expansion to fit window size after manual resizing

#mainloop
root.mainloop()
</code></pre>

<p>...it opens up and <em>initially looks exactly the same as before,</em> but now I can <em>manually</em> drag the box vertically to shrink it, like so:</p>

<p><a href="http://i.stack.imgur.com/D4mHc.png" rel="nofollow"><img src="http://i.stack.imgur.com/D4mHc.png" alt="enter image description here"></a></p>

<p>Notice how much more vertically-compressed it is! <strong>But, how do I do this programatically</strong>, so I don't have to <em>manually</em> drag it to make it this way? I want to set this tight vertical spacing from the start, but no matter which parameters I change in <code>Label</code>, <code>grid</code>, or <code>rowconfigure</code> I can't seem to make it work without me manually dragging the box with the mouse to resize and vertically compress the text.</p>

<p>You can programatically modify the geometry just before starting the main loop instead of manually dragging it (change 0.6 to whatever % reduction you want):</p>

<pre><code>import tkinter as tk  

#Create main window object 
root = tk.Tk()

#build GUI
for i in range(5):
    label = tk.Label(root, text = 'hello')
    label.grid(row=i)
    tk.Grid.rowconfigure(root, i, weight=1) #allow vertical compression/expansion to fit window size after manual resizing

#mainloop
root.update()
root.geometry("{}x{}".format(root.winfo_width(), int(0.6*root.winfo_height())))
root.mainloop()
</code></pre>

<p>Here is a screenshot of the result running on Xubuntu 16.04 LTS with Python 3.5.2:</p>

<p><a href="http://i.stack.imgur.com/Vovbe.png" rel="nofollow"><img src="http://i.stack.imgur.com/Vovbe.png" alt="enter image description here"></a></p>

python tkinter spacing