[Python] Is there a way to gray out (disable) a tkinter Frame?

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create a GUI in tkinter with two Frames, and have the bottom Frame grayed out until some event happens.

    Below is some example code:

    from tkinter import *
    from tkinter import ttk

    def enable():
    frame2.state(statespec='enabled') #Causes error

    root = Tk()

    #Creates top frame
    frame1 = ttk.LabelFrame(root, padding=(10,10,10,10))
    frame1.grid(column=0, row=0, padx=10, pady=10)

    button2 = ttk.Button(frame1, text="This enables bottom frame", command=enable)
    button2.pack()

    #Creates bottom frame
    frame2 = ttk.LabelFrame(root, padding=(10,10,10,10))
    frame2.grid(column=0, row=1, padx=10, pady=10)
    frame2.state(statespec='disabled') #Causes error

    entry = ttk.Entry(frame2)
    entry.pack()

    button2 = ttk.Button(frame2, text="button")
    button2.pack()

    root.mainloop()


    Is this possible without having to individually gray out all of the frame2's widgets?

    I'm using Tkinter 8.5 and Python 3.3.

    Continue reading...

Compartilhe esta Página