python-3.x - 如何更改继承自 ttk.Frame 的 Frame 类中容器的背景颜色?
问题描述
我想更改容器的背景颜色,但我无法做到。我的代码只改变了 frame1 的背景颜色。更改容器的背景颜色需要什么代码?
import tkinter as tk
from tkinter import ttk
class MainFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
self.style2 = {'fg': 'black', 'bg': '#e95420', 'activebackground': 'coral', 'activeforeground': '#2f2f2f'}
self.frame1 = ttk.Frame(self, padding = (0, 0, 0, 0), style='My.TFrame')
self.frame1.pack(fill="x", padx=0, pady=100, expand=False)
s = ttk.Style()
s.configure('My.TFrame', background='blue')
self.exit = tk.Button(self.frame1, compound=tk.RIGHT, text='Exit', width=20, relief="solid", command=container.exit)
self.exit.pack(expand=False, padx=0, pady=100, ipadx=10, ipady=10, side=tk.BOTTOM)
self.exit.configure(self.style2)
self.pack()
class StatusBar(tk.Frame):
def __init__(self, container):
super().__init__(container)
self.variable = tk.StringVar()
self.variable.set("add the current time here")
self.label=tk.Label(self, bd=0, relief="solid", height="2", width="1500", textvariable=self.variable, foreground="white", background='#2f2f2f', font=('helvetica',9))
self.label.pack()
self.pack(fill="x", side="bottom", ipady=0, padx=0, pady=0)
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("1500x1100")
def exit(self):
self.destroy()
if __name__ == "__main__":
app = App()
sb = StatusBar(app)
mf = MainFrame(app)
app.mainloop()
解决方案
推荐阅读
- javascript - VueJs 条件样式/类绑定?
- javascript - 如何根据另一个文本更改图标
- c# - Blazor 将输入文本发送回父组件
- jquery - 从其他 js 文件中检查简单的 js 函数是否存在不起作用
- java - 无法从命令行使用 maven 调用单个 junit 测试方法
- android - 我可以使用 android app bundle 在我的服务器上生成所需的 APK 吗?
- excel - VBA不计数,而是出错
- javascript - 如何从页面上的 URL 中删除 http(s)?
- jenkins-pipeline - 获取当前构建的阶段查看时间
- java - javabridge安装错误