I am making a rock paper scissor game but an error is coming.
from tkinter import *
from PIL import Image, ImageTk
def get_random_token():
tokens = ['rock', 'paper', 'scissor']
comp_token = random.choice(tokens)
print(comp_token)
return comp_token
def show_comp_token():
if get_random_token() == 'rock':
rock_token = ImageTk.PhotoImage(Image.open('./gallery/rock_token.png'))
comp_label.configure(image=rock_token, width=80, height=80)
comp_label.image = rock_token
if get_random_token() == 'paper':
paper_token = ImageTk.PhotoImage(Image.open('./gallery/paper_token.png'))
comp_label.configure(image=paper_token, width=80, height=80)
comp_label.image = paper_token
if get_random_token() == 'scissor':
scissor_token = ImageTk.PhotoImage(Image.open('./gallery/scissor_token.png'))
comp_label.configure(image=scissor_token, width=80, height=80)
comp_label.image = scissor_token
def logic():
if get_user_token() == 'rock':
if get_random_token() == 'rock':
return 'user TIE'
if get_random_token() == 'paper':
return 'user LOST'
if get_random_token() == 'scissor':
return 'user WON'
if get_user_token() == 'paper':
if get_random_token() == 'rock':
return 'user WON'
if get_random_token() == 'paper':
return 'user TIE'
if get_random_token() == 'paper':
return 'user LOST'
if get_user_token() == 'scissor':
if get_random_token() == 'rock':
return 'user LOST'
if get_random_token() == 'paper':
return 'user WON'
if get_random_token() == 'scissor':
return 'user TIE'
def main_func():
logic()
this is only some part of the program but the error is in this portion only.
when I run the program and print comp_token in the function get random tokens six instances get printed but I only want one and this is causing a problem.
please help
paper
scissor
scissor
rock
rock
rock