Tkinter - 分隔符小部件
Tkinter支持各种小部件,使 GUI 越来越有吸引力和功能性。 Separator 小部件用于对标签、按钮等tkinter小部件进行分区。使用此小部件我们可以使我们的设计更具吸引力和直观性。现在我们将看到如何实现这个小部件。
句法:
Separator(master, orient)
Parameters:
- master: parent widget or main Tk() object
- orient: vertical or horizontal
以下是描述在 Tkinter 中使用 Separator Widget 的程序:
垂直方向:
Python3
# Python programm to
# Illustrate Separator
# widget
# Import required modules
from tkinter import *
from tkinter import ttk
# Main tkinter window
x = Tk()
x.geometry("400x300")
# Label Widget
b = Label(x, bg="#f5f5f5", bd=4, relief=RAISED, text="With Separator")
b.place(relx=0.03, rely=0.1, relheight=0.8, relwidth=0.4)
# Separator object
separator = ttk.Separator(x, orient='vertical')
separator.place(relx=0.47, rely=0, relwidth=0.2, relheight=1)
# Label Widget
a = Label(x, bg="#f5f5f5", bd=4, relief=RAISED, text="With Separator")
a.place(relx=0.5, rely=0.1, relheight=0.8, relwidth=0.4)
mainloop()
Python3
# Python programm to
# Illustrate Separator
# widget
# Import required modules
from tkinter import *
from tkinter import ttk
# Main tkinter window
x = Tk()
x.geometry("400x300")
# Label Widget
b = Label(x, bg="#f5f5f5", bd=4, relief=RAISED, text="With Separator")
b.place(relx=0.1, rely=0.05, relheight=0.4, relwidth=0.8)
# Separator object
separator = ttk.Separator(x, orient='horizontal')
separator.place(relx=0, rely=0.47, relwidth=1, relheight=1)
# Label Widget
a = Label(x, bg="#f5f5f5", bd=4, relief=RAISED, text="With Separator")
a.place(relx=0.1, rely=0.5, relheight=0.4, relwidth=0.8)
mainloop()
输出:
在上面的程序中,将只生成没有分隔符的垂直输出。但是,没有分隔符的tkinter窗口如下所示:
水平方向:
蟒蛇3
# Python programm to
# Illustrate Separator
# widget
# Import required modules
from tkinter import *
from tkinter import ttk
# Main tkinter window
x = Tk()
x.geometry("400x300")
# Label Widget
b = Label(x, bg="#f5f5f5", bd=4, relief=RAISED, text="With Separator")
b.place(relx=0.1, rely=0.05, relheight=0.4, relwidth=0.8)
# Separator object
separator = ttk.Separator(x, orient='horizontal')
separator.place(relx=0, rely=0.47, relwidth=1, relheight=1)
# Label Widget
a = Label(x, bg="#f5f5f5", bd=4, relief=RAISED, text="With Separator")
a.place(relx=0.1, rely=0.5, relheight=0.4, relwidth=0.8)
mainloop()
输出:
在上面的程序中,将只生成没有分隔符的水平输出。但是,没有分隔符的tkinter窗口如下所示: