tkinter ttk separator won't display

bhaskarc picture bhaskarc · Jun 9, 2013 · Viewed 33.5k times · Source

Consider this simple code:

from Tkinter import *
import ttk
root= Tk()
ttk.Label(root, text='Heading Here').grid(row=1, column=1)
ttk.Separator(root,orient=HORIZONTAL).grid(row=2, columnspan=5)
root.mainloop()

When I run this code, the separator is almost invisible.
ttk separator not visible
I have marked it with a red arrow, if you can see it as a small dot kind of thing.

How do I make the separator span the entire horizontal width, or at least be visible?

Answer

Bryan Oakley picture Bryan Oakley · Jun 9, 2013

The separator has a natural width of 1 pixel. You told it to reserve the space across five columns, but you haven't requested that the separator actually fill those five columns. To solve this, supply the sticky attribute, which says "if there's more space than needed for this widget, make the edges of the widget "stick" to specific sides of its container".

In this case, you want the separator to sticky to the left and right edges of it's container. The sticky attributes uses the points of the compass for values, so you want "e" for east, and "w" for west:

ttk.Separator(...).grid(..., sticky="ew")