Skip to content
Advertisement

Entry not updating tkinter python

Im trying to make a rock paper scissors game using the python module tkinter to create a window with an input box. However im struggling to get the entry box to update to another value everytime i press the button.

JavaScript

What im struggling with i.e if I was to write Rock as an input (assume computer response is always 0):

Then my output would be 0 this is correct, however if my next input was something random like dsadsad the desired output would be 'Something went wrong with the input'. However it seems like the first input is saved and is continusly used since the output would still be 0.

If we on the other hand start with the input dsdasdasd the output would read: 'Something went wrong with the input'. And if we then wrote the input as rock the output would still read 'Something went wrong with the input' instead of the desired output 0.

Any help appreciated,

OBS! this might not be the most efficient way of programming this form of programm but im new to programming.

Advertisement

Answer

Your if statements are at fault. You are always comparing the user input with the first item on the list, with text[0], you need to change that to text[-1] to get the last item appended to the list. So your function would be:

JavaScript

You can also remove or and convert all text to lower or upper case and then compare between them. I am also assuming this is not the entire code, because some of your functions don’t have any true purpose (yet?) and returning from a button callback is of no use too.

Advertisement