1
>>> Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Maximillian\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Python-koding\steinsakspapir.py", line 64, in scissors
    botwin += 1
UnboundLocalError: local variable 'botwin' referenced before assignment

-Tried to remove botwin and youwin from rest of the code -Tried to use youwin = youwin + 1

    def scissors():
        bot = random.randint(1,3)
       user = 3
       if user == bot:
            printfuver = ("Stalemate, booth players choose scissors")
           printfu = Label(lowerframe, text=printfuver, fg="blue")
            printfu.pack()
        if user == 3 and bot == 1:
            printfuver = ("Rock crushes scissors, bot win! ")
            printfu = Label(lowerframe, text=printfuver, fg="red")
            printfu.pack()
            botwin += 1
        if user == 3 and bot == 2:
            printfuver = ("Scissors cut paper, you win! ")
            printfu = Label(lowerframe, text=printfuver, fg="green")
            printfu.pack()
            youwin += 1

Simply want botwin to increase with a value of 1 after each time the fuction is ran.

thanks in advance

Aaron_ab
  • 3,450
  • 3
  • 28
  • 42
Max B
  • 13
  • 3
  • 2
    if you want to increase the value by 1, you need to ensure the value exists beforehand. does `botwin` exist? does `youwin` exist? you can use them as global variables and increment outside. – Paritosh Singh Dec 30 '18 at 16:14
  • This may or may not be the issue, but it looks like you have an indentation issue in the `if user == bot:` block. `printfu = Lable(lowerframe, text=printfuver, fg="blue")` is one space back. Correct that and see if your code works. –  Dec 30 '18 at 16:24
  • thanks you, it worked. had to make it global – Max B Dec 30 '18 at 16:26

1 Answers1

0

Aside from the indentation error in your code, this is probably a scope issue. Check to make sure you have botwin = 0 or something like it somewhere in your code. If that code is in a function or otherwise out of global scope, put it at the top of your code. Then, in all functions that reference it, put global botwin at the beginning of your function as explained here.

I hope this helps you.