Skip to content
Advertisement

Tkinter App – TypeError: can only concatenate str (not “StringVar”) to str

I am trying to build a weather app in tkinter for class and I am stuck! I keep getting the following error message in the console:

JavaScript

Error Message from Visual Studio Code

Here’s my Python code:

JavaScript

So, the API I used is supposed to accept the zip code which is what I am collecting using:

JavaScript

I’m not sure how else I can collect the zip than with StringVar()

Any help/guidance would be extremely appreciated.

Advertisement

Answer

I suppose the content of zip should contain user input as integer. You can convert it to string using str():

JavaScript

Consider using a variable, e.g. zip_str, instead of calling str() multiple times.

You also might want to validate the user input.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement