Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:07:41+00:00 2026-06-06T00:07:41+00:00

How can I simply disable a TkInter Listbox? It seems such a straightforward thing

  • 0

How can I simply disable a TkInter Listbox? It seems such a straightforward thing to do and possibly it is. In the simple example below, I’ve got a button which should toggle the state of the listbox from fully selectable to greyed and unselectable.

#!/usr/bin/python

from Tkinter import *

class MyDialog:
    def __init__(self, rootWin):
        self.rootWin_ = rootWin
        self.frame_ = Frame( self.rootWin_, borderwidth=10 )
        self.frame_.grid(row=0, column=0)
        self.listBox_ = Listbox( self.frame_, height=4, width=30, selectbackground='#000000' )
        self.listBox_.grid(row=0, column=0)
        self.lbEnabled_ = 1
        for item in [ 'Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet' ]:
            self.listBox_.insert(END, item)
        self.button_ = Button( self.frame_, text='Disable', command=self.onEnableDisable)
        self.button_.grid(row=1, column=0)

    def go(self):
        self.rootWin_.mainloop()

    def onEnableDisable(self):
        if self.lbEnabled_ == 1:
            self.button_.config( text='Enable' )
            # TODO enable the list box
            self.lbEnabled_ = 0
        else:
            self.button_.config( text='Disable' )
            # TODO disable the list box
            self.lbEnabled_ = 1

def main():
    myDlg = MyDialog(Tk())
    myDlg.go()

if __name__ == '__main__':
    main()

I’ve tried a few things including changing state:

self.listBox_.config( state = DISABLED )

The reference documentation I’ve found suggests you can set this with the state attribute:

state By default, a listbox is in the NORMAL state. To make the listbox unresponsive to mouse events, set this option to DISABLED.

However, if I try this, all I get is:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "./example.py", line 24, in onEnableDisable
    self.listBox_.config( state = DISABLED )
  File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1139, in configure
    return self._configure('configure', cnf, kw)
  File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1130, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: unknown option "-state"

As you can see, I’m using a pretty old version (2.4) of python which probbaly won’t help, but I have no control over. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:07:42+00:00Added an answer on June 6, 2026 at 12:07 am

    Your proposed code works for me (python 2.6, OS-X). It actually looks like Tkinter is doing the right thing from the traceback. Perhaps you’re also using an old version of Tcl/Tk which could also cause the problem you’re seeing. If you don’t have control over the python version, do you have control over the Tk version?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’ve read that you can disable (make physically unclickable) an HTML button simply by
This seems to be something obvious but I simply can't find info by googling.
IE9 users can disable an add-on, such as a browser helper object, by clicking
Below is a self-contained application you can run. It simply displays a spark combo
I'm trying to make an applet which I can simply drag an image. And
I hate generating an exception for things that I can simply test with an
When you declare a type parameter for the class, you can simply use that
I simply can not get Visual Studio 2005 to find the System.Configuration.ConfigurationManager class. Here
In Python, how can I simply do the equivalent of dictionary.get(key, default) for lists
I know I should do my homework on my own but I simply can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.