Tkinter Separator
When designing GUI programs, sometimes adding separators at the right places can make the overall visual effect better. tkinter.ttk has the Separator module, which can be used to do this, and its syntax format is as follows.
Separator(master, options)
The first parameter of the Separaetor() method is the parent object, indicating which parent the separator will be created in; the options parameter is HORIZONTAL to create a horizontal separator, and VERTICAL to create a vertical separator.
Tkinter Separator Example
Create separator lines between Labels.
"""
Tkinter Separator example
"""
from tkinter import *
from tkinter.ttk import Separator
root = Tk()
root.title("apidemos.com")
myTitle = 'www.apidemos.com'
myContent = """Wlecome to apidemos.com
Wlecome to apidemos.com
Wlecome to apidemos.com
Wlecome to apidemos.com
Wlecome to apidemos.com
Wlecome to apidemos.com
Wlecome to apidemos.com
Wlecome to apidemos.com
"""
lab1 = Label(root,text=myTitle,font="Helvetic 20 bold")
lab1.pack(padx=10,pady=10)
sep = Separator(root,orient=HORIZONTAL)
sep.pack(fill=X,padx=5) # indicates that the split line fills the X-axis and is 5 pixels away from both the left and right borders of the window
lab2 = Label(root,text=myContent)
lab2.pack(padx=10,pady=10)
root.mainloop()
Output:
Line 25 of the above program: pack(fill=X,padx=5)
, indicates that this separator line fills the X-axis, which is 5 pixels away from the window border on both the left and right.