Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
679 views
in Technique[技术] by (71.8m points)

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

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!

enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...