[Tutor] Disabling a frame in Tkinter

Hans Dushanthakumar Hans.Dushanthakumar at navman.com
Fri Jan 6 03:20:55 CET 2006

Thanks John,
   Yup the code you provided disables all child-widgets:

    def setState(self, widget, state='disabled'):
        print type(widget)
        except Tkinter.TclError:
        for child in widget.winfo_children():
            self.setState(child, state=state)


-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of John Fouhy
Sent: Friday, 6 January 2006 12:03 p.m.
To: tutor at python.org
Subject: Re: [Tutor] Disabling a frame in Tkinter

On 06/01/06, Hans Dushanthakumar <Hans.Dushanthakumar at navman.com> wrote:
> Hi,
>    Is there any way to disable an entire frame (and all its included
> widgets) in Tkinter. It does not seem to support state=DISABLED.

Not that I'm aware of...  You could try maybe something like this

def setState(widget, state=DISABLED):
  except TclError:   # not sure what exception will be raised
  for child in widget.children:
    setState(child, state=state)

> Another Tkinter question: In a listbox, how do I intially set a 
> "selected" item? What I want to do here is have the 1st item in a 
> listbox selected (ie highlighted) when the appln is run.

Have a look at Fredrik Lundh's Introduction to Tkinter.  You can use
.selection_clear() to clear the selection and .selection_set(index) to
select an item. So, .selection_set(0) will select the first item (just
make sure the listbox isn't empty).

Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list