Python Forum
ValueError: could not convert string to float: '' fron Entry Widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: could not convert string to float: '' fron Entry Widget
#1
Hello,

I have a simple program that takes user input from a tkinter entry widget and then converts the user input to a float for processing.

I am using Stringvar linked to the entry-textvariable and trace_add to monitor when the contents of the entry widget change to then call the function for processing

That is all working when a correct entry is passed, the issue I am seeing however is when the entry widget gains focus and the current contents are selected.

If I then type a new entry, effectively overwriting the contents of the entry widget, a call to the trace is made twice.

This first time containing '' which then gives the error ValueError: could not convert string to float: ''
A second call is then made with the values I have typed in the entry box and it all works fine.

I cannot figure out why Stringvar is set to '' when I enter a value into the entry widget.

Can anyone help me understand why this is happening and how to fix it?

Thanks.
Reply


Messages In This Thread
ValueError: could not convert string to float: '' fron Entry Widget - by russellm44 - Mar-04-2024, 06:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] entry widget DPaul 5 1,612 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  Get string from entry and use it in another script amdi40 1 1,449 Jan-26-2022, 07:33 PM
Last Post: Larz60+
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,083 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,318 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 7,015 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 6,132 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,511 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to retreive the grid location of an Entry widget kenwatts275 7 4,749 Apr-24-2020, 11:39 PM
Last Post: Larz60+
  POPUP on widget Entry taratata2020 4 3,825 Mar-10-2020, 05:04 PM
Last Post: taratata2020
  [Tkinter] manipulation of string in Text widget Stauricus 2 3,106 Feb-17-2020, 09:23 PM
Last Post: Stauricus

Forum Jump:

User Panel Messages

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