Skip to content
Advertisement

Tkinter Window: TypeError: can only concatenate str (not “int”) to str

I’m having trouble solving the Concatenate Error when it’s present in a Tkinter Window. I tried using multiple methods but, they didn’t work to well with what I’m trying to do. I’m trying to make it so where, at the click of a Tkinter button, it would randomly choose a value between 0 and 100. If the random value is less than or equal to 70, both “Good Guy” and “Bad Guy” would have their health reduced. But if it’s greater than 70, Good guy would only take damage. It would then print their new hp into the window.

JavaScript

Advertisement

Answer

i suspect the issue is here:

JavaScript

what type is G? if it’s an int you cannot add them together like you’re trying to do, you need to change it to text="Goodguy Hp: " + str(G), or use an f-string like @AKX mentioned

try changing this expression in all four places

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