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>There are many ways to affect vertical spacing. </p>

<p>When you use <code>grid</code> or <code>pack</code> there are options for padding (eg: <code>pady</code>, <code>ipady</code>, <code>minsize</code>). Also, the widget itself has many options which control its appearance. For example, in the case of a label  you can set the <code>borderwidth</code>, <code>highlightthickness</code> and <code>pady</code> values to zero in order to make the widget less tall. </p>

<p>Different systems have different default values for these various options, and for some of the options the default is something bigger than zero. When trying to configure the visual aspects of your GUI, the first step is to read the documentation, and look for options that affect the visual appearance. Then, you can start experimenting with them to see which ones give you the look that you desire.</p>

<p>In your specific case, this is about the most compact you can get:</p>

<pre><code>label = tk.Label(root, highlightthickness=0, borderwidth=0, pady=0, text="hello")
label.grid(row=i, pady=0, ipady=0)
</code></pre>

python tkinter spacing