-3

Using python3.7 and tkinter to make a GUI, where I grab the input from 2 text boxes, and use a math formula then export it out.

I've looked through other forms and tried what they suggested and could not find how to fix it. I've tried global inside and outside of the function, setting the variable before the function.

def retrieve_input():
    global InputValue
    global InputValue2
    global Delay
    InputValue=tasks.get()
    InputValue2=proxies.get()
    print(InputValue)
    print(InputValue2)
    Delay=3500/int(InputValue)*int(InputValue2)
    print(Delay)
retrieve_input()
Label (window, width=12, text=Delay,bg="white",fg="Pink", font="none 22 bold") .grid(row=5, column=0,sticky=W)

Error:

  File ", line 29, in retrieve_input
    Delay=3500/int(InputValue)*int(InputValue2)
ValueError: invalid literal for int() with base 10: ''
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    You're trying to convert an empty string to an int as the error says. Check your inputs. – Carcigenicate Jul 08 '19 at 00:32
  • @Carcigenicate yes I know, I just don't know how to make it not empty as I need to wait for the client to use it. – isuckatcoding Jul 08 '19 at 00:33
  • 1
    You would call this function when the textbox is modified (https://stackoverflow.com/questions/6548837/how-do-i-get-an-event-callback-when-a-tkinter-entry-widget-is-modified) or when some kind of submit button is pressed. – Carcigenicate Jul 08 '19 at 00:37
  • The answer is in the question you just asked. You need to wait for the client to use the textbook. So don't run the code until that's happened. – Silvio Mayolo Jul 08 '19 at 00:40
  • Instead of `int(InputValue2)`, you could use `0 if not InputValue else int(InputValue)` (replace `0` with whatever you want the default value to be). – martineau Jul 08 '19 at 00:41
  • martineau still got the same error. @Carcigenicate I have a submit button, not sure how to make so it's not empty until but I will try the other way, thanks. – isuckatcoding Jul 08 '19 at 00:47
  • @isuckatcoding In the submit button `action` callback, do an `if InputValue and InputValue2:` check to make sure they're both non-empty, and if they're not empty, then call `retrieve_input`. – Carcigenicate Jul 08 '19 at 00:51
  • @Carcigenicate I added the callback function, I don't know where to put the `if InputValue and InputValue2:` – isuckatcoding Jul 08 '19 at 00:57

1 Answers1

1

It means that you are passing in an empty string to the int class constructor. You are effectively calling int(''). It looks like either tasks.get() or proxies.get() are returning the empty string.

In Short: Don't pass an empty string to int().

As for the comment you left:

try:
    Delay=3500/int(InputValue)*int(InputValue2)
except ValueError:
    pass
    #Handle a case in which the input is ''
JonPizza
  • 129
  • 1
  • 11