Thanks to visit codestin.com
Credit goes to github.com

Skip to content

entry state="readonly" --> visualize the read only state #63

@Pommes1024

Description

@Pommes1024

Hi,

I noticed the read only state on entries is not graphically represented as in stock tkinter, where the background is turned grey.
An editable entry looks just the same as a not-editable one.
Is there a quick fix for this?

Here is an example app to showcase the issue.
Just # the two root.tk.call lines to see the expected behaviour without the theme.

Thank you in advance!

import tkinter as tk
from tkinter import ttk


class App(ttk.Frame):
    def __init__(self, parent):
        ttk.Frame.__init__(self)
        # Create widgets :)
        self.setup_widgets()

    def setup_widgets(self):
        # Create a Frame for the Checkbuttons
        self.check_frame = ttk.LabelFrame(self, text="Checkbuttons", padding=(20, 10))
        self.check_frame.grid(
            row=0, column=0, padx=(20, 10), pady=(20, 10), sticky="nsew"
        )


        # Create a Frame for input widgets
        self.widgets_frame = ttk.Frame(self, padding=(0, 0, 0, 10))
        self.widgets_frame.grid(
            row=0, column=1, padx=10, pady=(30, 10), sticky="nsew", rowspan=3
        )

        # Entry
        self.entry = ttk.Entry(self.widgets_frame)
        self.entry.insert(0, "Entry editable")
        self.entry.config(state="write")
        self.entry.grid(row=0, column=0, padx=5, pady=(0, 10), sticky="ew")

        self.entry2 = ttk.Entry(self.widgets_frame)
        self.entry2.insert(0, "Not editable")
        self.entry2.config(state="readonly")
        self.entry2.grid(row=0, column=1, padx=5, pady=(0, 10), sticky="ew")


if __name__ == "__main__":
    root = tk.Tk()
    root.title("")

    # Simply set the theme
    root.tk.call("source", "azure.tcl")
    root.tk.call("set_theme", "dark")

    app = App(root)
    app.pack(fill="both", expand=True)

    # Set a minsize for the window, and place it in the middle
    root.update()
    root.minsize(root.winfo_width(), root.winfo_height())
    x_cordinate = int((root.winfo_screenwidth() / 2) - (root.winfo_width() / 2))
    y_cordinate = int((root.winfo_screenheight() / 2) - (root.winfo_height() / 2))
    root.geometry("+{}+{}".format(x_cordinate, y_cordinate-20))

    root.mainloop()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions