I am currently creating a fitness app on Python 3's Tkinter.
Here is the code I have so far.
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()
Once the code is run, you can see what this looks like. I want to create a solid thin white line running across from the left side to the right side, in order to separate this from the rest of the code I plan to implement.
Given the code I already have, how can I do this?
There is a ttk widget made for that: ttk.Separator(master, orient=..., style=...). The orient option is either 'vertical' or 'horizontal'.
To make it fill your window from left to right, as fhdrsdg said in the comments, you can pack it using the option fill='x'.
Here is an example:
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()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With