Search code examples
pythontkinterspinnertkinter-entry

Python 2.5 Tkinter Highlight Spinbox Entry


This question seems trivial to me but I can't seem to find anything related to it, and the Spinbox docs don't seem to help.

Is there any way to select all of the text in a Spinbox widget?

I'm currently trying:

self.spinbox.selection_clear()
self.spinbox.selection('range', 0, END)

to no avail.

I have this bound to a mouse-click on the spinbox. The first time you click on it, all the entry text will be highlighted, and subsequent times it will not, unless a boolean variable has been reset. I've had no problem doing this with entry widgets, but this spinbox seems to give me trouble. Am I using the function wrong?


Solution

  • From experimentation, I think the Spinbox needs to explicitly have focus in order for selection to do anything. Try:

    self.spinbox.selection_clear()
    self.spinbox.focus_set()
    self.spinbox.selection('range', 0, END)