gpt4 book ai didi

Python 3 Tkinter : How can I create a solid white line to partition widgets from the rest of the program?

转载 作者:行者123 更新时间:2023-12-01 01:53:39 26 4
gpt4 key购买 nike

我目前正在 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()

运行代码后,您可以看到它的样子。我想创建一条从左侧到右侧的实心细白线,以便将其与我计划实现的其余代码分开。

鉴于我已有的代码,我该如何执行此操作?

最佳答案

有一个专门为此设计的 ttk 小部件:ttk.Separator(master, orient=..., style=...)。方向选项是“垂直”或“水平”。

要使其从左到右填充您的窗口,正如 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()

screenshot

关于Python 3 Tkinter : How can I create a solid white line to partition widgets from the rest of the program?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50463005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com