In this post we will learn how to use Separators inside our tkinter application. There are few times, were we would like to mention some important point or separate a contents inside tkinter window. Tkinter has a widgets named Separator which would allow us to draw both horizontal or vertical line. Lets get started,
IN[1]
import tkinter as tk
from tkinter import ttk
try:
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
except:
pass
root = tk.Tk()
root.title("Seperator")
root.geometry("400x150")
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
l1 = ttk.Label(root, text="First Line", padding=20).pack()
s1 = ttk.Separator(root, orient="horizontal").pack(fill='x')
l2 = ttk.Label(root, text="Second Line", padding=20).pack()
root.mainloop()
OUT[2]
We define two labels l1 and l2 so that we can define separator to distinguish these two labels l1 and l2. To define separator use Separator class. The followings are the arguments and their properties,
Orient : Can be both Horizontal and Vertical, describes line position.
Style : The style to be used in rendering this scrollbar.
From the above snap you can see after defining Separator that a 2px of black line drawn between the Label 1 and 2.