question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spinbox widget breaks when I use backspace to delete all its contents

See original GitHub issue

Hi thanks a lot for this fantastic project, I’ve been learning to use it, and I really like it.

Recently I hit below error when I using a SpinBox and want to correct the actual value myself and set manually.

Let’s say spinbox, shows 500 as value and I wanted to set it to 1, or any other number, when you use back space key there, all is ok if you DO NOT delete all text(numbers) in there, when you delete last digit then this happens:

Traceback (most recent call last):
  File "/Users/larrycastro/Documents/workspace/lab-constructor/./lab-constructor.py", line 1960, in <module>
    tui_menu()
  File "/Users/larrycastro/Documents/workspace/lab-constructor/./lab-constructor.py", line 1884, in tui_menu
    rootWindow.mainloop()
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 113, in mainloop
    self._mainLoop()
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 122, in _mainLoop
    self._input.start()
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/TTkTerm/input.py", line 77, in start
    self.key_process(stdinRead)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/TTkTerm/input.py", line 155, in key_process
    self.inputEvent.emit(kevt, mevt)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/signal.py", line 123, in emit
    slot(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 128, in _processInput
    self._key_event(kevt)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 188, in _key_event
    keyHandled = focusWidget.keyEvent(kevt)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkWidgets/spinbox.py", line 84, in keyEvent
    return TTkLineEdit.keyEvent(self._lineEdit, evt)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkWidgets/lineedit.py", line 233, in keyEvent
    self.textEdited.emit(self._text)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkCore/signal.py", line 123, in emit
    slot(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/TermTk/TTkWidgets/spinbox.py", line 73, in _textEdited
    self.setValue(int(text))
ValueError: invalid literal for int() with base 10: ''

I’m thinking to do a workaround at the valueChanged to catch all there and prevent this exception… not sure if this can work…,

I also think this is a bug, because I just tried on your online sandbox, and I think it breaks (https://ceccopierangiolieugenio.github.io/pyTermTk/sandbox/sandbox.html) widgets at spinxbox field example.

Please let me know if you need any ohter info from me. Regards

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
castbencommented, Sep 30, 2022

Hi @ceccopierangiolieugenio,

I do apologize!, I’m sorry I found issue. it was totally my fault!

How i discovered this issue:

  1. I’ve recreated a simple frame and window, then added spinbox… it worked perfectly no defects at all…
  2. Add few pieces of my code…
  3. and the problem popped up… then sneaked into the code, and found the culprit:
    @pyTTkSlot()
    def spinbox_value(self, value=None):
        """

        :param value:
        :return:
        """
        print(value)                                 <----------------- here is it!
        if value == '':
            return 0

Do you remember I was trying to setup this to find out if I was able to capture exception (which I was ovbiusly wrong) because it will break anyway without your changes.

then I totally forgot to get rid of this…

I’m sorry for waste your time.

You can consider this bug fixed. Thank you for your patience and fast fix.

0reactions
ceccopierangiolieugeniocommented, Sep 30, 2022

heheh, no worries,

Actually I was wondering if you used something like copy and paste to change the value since I think that some widgets are still not protected from ANSI escape codes or control chars i.e. “\t” “\n”.

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entry Tkinter is not allowing to erase data if selected all and ...
But i am not able to select all in the entry box and delete them using delete or backspace keys, could somebody help...
Read more >
23. The Spinbox widget
The Spinbox widget allows the user to select values from a given set. The values may be a range of numbers, or a...
Read more >
QSpinBox - wont accept 'backspace' or 'del' keypresses
Now when the user clicks on the spinBox, cursor stays at the rightmost end, and the text ("--") will not clear off if...
Read more >
Understanding Tkinter Event Binding Clearly - Python Tutorial
In this tutorial, you'll learn about the Tkinter event binding and how to use it to associate a function to an event of...
Read more >
spinbox manual page - Tk Built-In Commands - Tcl/Tk
Specifies one of three states for the spinbox: normal, disabled, or readonly. If the spinbox is readonly, then the value may not be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found