Tkinter - Can I change the background color for a TTK Label set in ReadOnly mode? I tried but it didn't work

随声附和 提交于 2021-02-11 12:30:07

问题


In according with the TTK documentation, in my code, I tried to change the background color only for the TTK labes placed in readonly mode, but unfortunately it didn't work. I replicated the issue below:

from tkinter import *
from tkinter import ttk

class MainWindow:
    def __init__(self):
        self.parent=Tk()
        self.parent.geometry("350x250")
        self.parent.title("Test")
        self.parent.configure(background="#f0f0f0")

        style=ttk.Style()
        # only the "foreground" option works, but the "background" one not. why?
        style.map("TEntry", background=[("readonly", "white")], foreground=[("readonly", "red")])
        
        self.MyEntrySV=StringVar()
        self.MyEntry=ttk.Entry(self.parent, textvariable=self.MyEntrySV, state="readonly", width=48)
        self.MyEntrySV.set("why is background grey and not white?")
        self.MyEntry.place(x=10, y=10)
        
        self.parent.mainloop()

obj=MainWindow()

I'm working on Windows 10 Professional x64. if nobody knows how to solve the issue, how can I contact the Tkinter team? from my side it's a really frustrating issue and I want to solve it!

来源:https://stackoverflow.com/questions/65895321/tkinter-can-i-change-the-background-color-for-a-ttk-label-set-in-readonly-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!