我目前正在Python 3的Tkinter上创建一个健身应用程序。
这是我到目前为止的代码。
import tkinter as tk
from tkinter import *
root = Tk()
root.geometry("1600x1000+0+0")
root.title("Ultimate Fitness Calculator")
root.configure(bg='darkslategray')
lbl_title = tk.Label(root,text="Welcome to the Ultimate Fitness Calculator by Cameron Su.", fg="white", bg = 'darkslategray')
lbl_title.pack()
Tops = Frame(root, width=1600, height=50, bg="darkslategray", relief=SUNKEN)
Tops.pack(side=TOP)
f1 = Frame(root, width=1600, height=900, bg="darkslategray", relief=SUNKEN)
f1.pack(side=LEFT)
lblInfo = Label(Tops, font=('Gill Sans', 50), text="Ultimate Fitness Calculator", fg="white",bg="darkslategray", bd=10, anchor='w').grid(row=0, column=0)
lblInfo = Label(Tops, font=('Gill Sans', 20), text="This multifunctional program calculates Basal Metabolic Rate, Total Daily Energy Expenditures \n and breaks down the amount of macronutrients needed to reach your fitness goals.", fg="white",bg="darkslategray",
bd=10, anchor='w').grid(row=1, column=0)
root.mainloop()
运行代码后,您可以看到它的外观。我想在左侧到右侧创建一条坚固的细白线,以便将其与我计划实现的其余代码分开。
鉴于我已有的代码,我该怎么做?
答案 0 :(得分:1)
为此制作了一个ttk小部件:ttk.Separator(master, orient=..., style=...)
。 Orient选项是' vertical'或者横向'。
要让它从左到右填充你的窗口,正如fhdrsdg在评论中所说,你可以使用fill='x'
选项打包它。
以下是一个例子:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
frame1 = tk.Frame(root)
separator = ttk.Separator(root, orient='horizontal')
frame2 = tk.Frame(root)
frame1.pack(side='top', fill='both', expand=True)
separator.pack(side='top', fill='x')
frame2.pack(side='top', fill='both', expand=True)
tk.Label(frame1, text='This is the top part.').pack()
tk.Label(frame2, text='This is the bottom part.').pack()
root.mainloop()