ttk.框架背景色

2024-09-30 18:27:13 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使页面框架的背景色为绿色?pageframe是包含一些文本的框架。我尝试过很多关于ttk样式的网站,但是我的代码仍然没有显示绿色背景,即使我使用了样式。在

context=我正在为我的项目创建饮食和运动管理程序,但只是这个绿色的背景色不起作用。在

我提供了一个图片,它看起来如何。在

我只包含了代码的相关部分。在

我也喜欢用ttk.框架()而不仅仅是框架()

Diet and exercise management program

from tkinter import *
from tkinter import ttk



root = Tk()
root.geometry('500x400')
root.grid_columnconfigure(0, weight=1)#This configures the column and row to be weighted.
root.grid_rowconfigure(0, weight=1)


main = ttk.Frame(root, padding = (3,3,3,3))#This creates the padding around all the contents.
main.grid(column=0, row=0, sticky=(N,W,E,S))
main.grid_columnconfigure(1, weight=1)
main.grid_rowconfigure(4, weight=1)




pagestyle = ttk.Style()
pagestyle.configure("G.TFrame" , background='green')

nav = ttk.Frame(main, borderwidth=2)
nav.grid(column=0, row=0, rowspan = 4, sticky=(N,W,E,S))


pageframe = ttk.Frame(main,style="G.TFrame" )
pageframe.grid(column = 1, row = 0, rowspan =5, sticky=(N,W,E,S))
pageframe.columnconfigure(0, weight=1)


text = Label(pageframe , text="Home")
text.grid(column=0, row=0)

text = Label(pageframe , text="Weekly Overview")
text.grid(column=0, row=1)

Tags: thetext框架maincolumnrootframegrid