Python Forum
[Tkinter] Validating and modifying a Spinbox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Validating and modifying a Spinbox
#3
Hi,

Would like to share a link to the complete solution: PasswordGeneratorGUI.

The SpinBox control proved particularly challenging to fine tune it to where I wanted to get it.

The up and down arrows always worked as expected but I was never able to easily manage if someone typed in an invalid string in the box. I was expecting that if someone typed in, dd, I could capture an onChange or onFocusLost event out of the box and take corrective action.

I found that pressing Tab did not cause the SpinBox to loose focus (even though the cursor would jump).

The lines below seem to have done the trick.

        self.root.bind('<Return>', self.reset_focus)
        self.root.bind('<Tab>', self.reset_focus)
Still not sure whether it could have been achieved without the need to code them in (they are built into the tool).



Another observation is that the name of the spinbox I define in python is different from that in Tcl/tk (widget) and I can't figure out how to get from the python name to the internal equivalent. Can one get to this via
(self.root.register(self.ValidateIfNum),'%P', '[b]%W[/b]')
?

With one spinbox the solution is manageable.

Thanks for any comments
Reply


Messages In This Thread
Validating and modifying a Spinbox - by pfdjhfuys - May-20-2023, 03:24 PM
RE: Validating and modifying a Spinbox - by pfdjhfuys - May-21-2023, 12:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] [Solved]Add a SpinBox to MsgBox or Carry Variable Over? Extra 6 1,871 Jun-05-2022, 09:32 PM
Last Post: Extra
  [Tkinter] how to celect com port from spinbox and make connect button 00alkskodi00 0 2,474 Apr-20-2020, 02:26 PM
Last Post: 00alkskodi00

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020