This is a minor issue but I’ve been struggling with it most of the afternoon and getting nowhere, so here goes. I’m about to write a Python script that will require the use of the ScrolledListBox(). Never having used it before, I started with an experimental script where I could play with it and get familiar with it. I now have the script to where I can double click on an item and, in the handler, correctly print the selected item to stdout. However, I notice that when the item is selected, either with a single or double click, a rectangular border appears around the item in the list and remains there until another item is selected. I’ve been trying to see if there’s a way to get rid of this border but so far have been unable to do so. Here’s what I’ve tried:
1) Thanks to another post in this forum I found that the keys() method would give me a list of the available options for the widget. So, given a ScrolledListBox named slb1 I could do something like print(slb1.keys()) and I got the full list of everything I could configure on the widget. One of them was ‘selectborderwidth’ so I did: slb1.configure(selectborderwidth=0) thinking that this would remove the border. It didn’t.
2) Next I dug through my copy of “Python and Tkinter” and discovered the selection_clear(first, last=None) method. The description states, “If any of the elements between first and last (inclusive) are selected, they are deselected.” So I tried: slb1.selection_clear(0, None) in the handler but once again the rectangular border around the item remained.
I’m just getting started in Python and Tkinter so hopefully I’m missing something somebody with more experience knows about. Any ideas on how to get rid of the border?
Thanks, Dave
Advertisement
Answer
The documentation by New Mexico Tech, which can be a good reference when working with Tkinter, lists the attributes for the Listbox
widget, among which activestyle
. This parameter refers to the box around the currently active (not necessarily selected) item, and can take the values underline
, dotbox
, and none
.
If you set activestyle
to none
, the dotted border will go away.