title: How to check who won in rock, paper, scissors- user vs computer- Python Tkinter
body: <p>I'm working on a rock, paper scissors game- user vs computer in Python tkinter. I'm struggling in the check function- the if statements in that function always evaluate to false for some reason (I checked by adding an else statement and printing something, and the program ended up going to the else statement every time). Can someone help me construct better if statements that check who won?
  My code:</p>
  <pre><code>from tkinter import *
  from random import randint
  from tkinter import messagebox
  
  window = Tk()
  window.title(&quot;Rock, Paper, Scissors&quot;)
  window.geometry(&quot;800x600+220+10&quot;)
  window.configure(bg=&quot;#fbfcbc&quot;)
  
  title = Label(window, text=&quot;Rock Paper Scissors:\nUser vs. Computer&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 30), fg=&quot;#f59c97&quot;,
                bg=&quot;#fbfcbc&quot;)
  title.place(x=200, y=10)
  count = 0
  computer_choice = None
  chosen = []
  
  
  images_list = [
      PhotoImage(file=&quot;images/rock.png&quot;),
      PhotoImage(file=&quot;images/paper.png&quot;),
      PhotoImage(file=&quot;images/scissors.png&quot;)
  ]
  
  
  def user_choice():
      global count
  
      user_choice_button.configure(text=&quot;&quot;, image=images_list[count])
      user_choice_button.place(x=120, y=320)
      count += 1
  
      if count == 3:
          count = 0
  
  
  def start():
      global computer_choice
  
      try:
          while chosen[-1] == computer_choice:
              computer_choice = images_list[randint(0, 2)]
          chosen.append(computer_choice)
      except IndexError:
          computer_choice = images_list[randint(0, 2)]
          chosen.append(computer_choice)
  
      computer_choice_label.configure(image=computer_choice, text=&quot;&quot;)
      check()
  
  
  def check():
      if user_choice_button[&quot;image&quot;] == images_list[0] and computer_choice_label[&quot;image&quot;] == images_list[1]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The computer won!&quot;)
      elif user_choice_button[&quot;image&quot;] == images_list[1] and computer_choice_label[&quot;image&quot;] == images_list[0]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;You won!&quot;)
      elif user_choice_button[&quot;image&quot;] == images_list[0] and computer_choice_label[&quot;image&quot;] == images_list[2]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;You won!&quot;)
      elif user_choice_button[&quot;image&quot;] == images_list[2] and computer_choice_label[&quot;image&quot;] == images_list[0]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The computer won!&quot;)
      elif user_choice_button[&quot;image&quot;] == images_list[1] and computer_choice_label[&quot;image&quot;] == images_list[2]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The computer won!&quot;)
      elif user_choice_button[&quot;image&quot;] == images_list[2] and computer_choice_label[&quot;image&quot;] == images_list[1]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;You won!&quot;)
      elif user_choice_button[&quot;image&quot;] == computer_choice_label[&quot;image&quot;]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The game ended in a draw!&quot;)
  
  
  def reset():
      user_choice_button.configure(text=&quot;Click to\nchoose&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 40))
      user_choice_button.place(x=50, y=300)
      computer_choice_label.configure(text=&quot;The computer's\nchoice will be\ndisplayed here&quot;,
                                      font=(&quot;Arial Rounded MT Bold&quot;, 30))
      computer_choice_label.place(x=450, y=310)
  
  
  user_choice_button = Button(window, text=&quot;Click to\nchoose&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 40), bg=&quot;#b6f5f8&quot;,
                              fg=&quot;#f59c97&quot;, command=user_choice)
  user_choice_button.place(x=50, y=300)
  computer_choice_label = Label(window, text=&quot;The computer's\nchoice will be\ndisplayed here&quot;,
                                font=(&quot;Arial Rounded MT Bold&quot;, 30), bg=&quot;#fbfcbc&quot;, fg=&quot;#f59c97&quot;)
  computer_choice_label.place(x=450, y=310)
  start_button = Button(window, text=&quot;START&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 30), bg=&quot;lime&quot;, command=start)
  start_button.place(x=300, y=200)
  
  
  window.mainloop()
  </code></pre>
  <p>A big thanks to jasonharper for solving the problem! Updated code:</p>
  <pre><code>from tkinter import *
  from random import randint
  from tkinter import messagebox
  
  window = Tk()
  window.title(&quot;Rock, Paper, Scissors&quot;)
  window.geometry(&quot;800x600+220+10&quot;)
  window.configure(bg=&quot;#fbfcbc&quot;)
  
  title = Label(window, text=&quot;Rock Paper Scissors:\nUser vs. Computer&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 30), fg=&quot;#f59c97&quot;,
                bg=&quot;#fbfcbc&quot;)
  title.place(x=200, y=10)
  count = 0
  computer_choice = None
  chosen = []
  
  
  images_list = [
      PhotoImage(file=&quot;images/rock.png&quot;),
      PhotoImage(file=&quot;images/paper.png&quot;),
      PhotoImage(file=&quot;images/scissors.png&quot;)
  ]
  
  
  def user_choice():
      global count
  
      user_choice_button.configure(text=&quot;&quot;, image=images_list[count])
      user_choice_button.place(x=120, y=320)
      count += 1
  
      if count == 3:
          count = 0
  
  
  def start():
      global computer_choice
  
      try:
          while chosen[-1] == computer_choice:
              computer_choice = images_list[randint(0, 2)]
          chosen.append(computer_choice)
      except IndexError:
          computer_choice = images_list[randint(0, 2)]
          chosen.append(computer_choice)
  
      computer_choice_label.configure(image=computer_choice, text=&quot;&quot;)
      check()
  
  
  def check():
      if user_choice_button[&quot;image&quot;] == str(images_list[0]) and computer_choice_label[&quot;image&quot;] == str(images_list[1]):
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The computer won!&quot;)
      elif user_choice_button[&quot;image&quot;] == str(images_list[1]) and computer_choice_label[&quot;image&quot;] == str(images_list[0]):
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;You won!&quot;)
      elif user_choice_button[&quot;image&quot;] == str(images_list[0]) and computer_choice_label[&quot;image&quot;] == str(images_list[2]):
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;You won!&quot;)
      elif user_choice_button[&quot;image&quot;] == str(images_list[2]) and computer_choice_label[&quot;image&quot;] == str(images_list[0]):
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The computer won!&quot;)
      elif user_choice_button[&quot;image&quot;] == str(images_list[1]) and computer_choice_label[&quot;image&quot;] == str(images_list[2]):
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The computer won!&quot;)
      elif user_choice_button[&quot;image&quot;] == str(images_list[2]) and computer_choice_label[&quot;image&quot;] == str(images_list[1]):
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;You won!&quot;)
      elif user_choice_button[&quot;image&quot;] == computer_choice_label[&quot;image&quot;]:
          messagebox.showinfo(&quot;Rock, Paper, Scissors&quot;, &quot;The game ended in a draw!&quot;)
  
  
  def reset():
      user_choice_button.configure(text=&quot;Click to\nchoose&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 40))
      user_choice_button.place(x=50, y=300)
      computer_choice_label.configure(text=&quot;The computer's\nchoice will be\ndisplayed here&quot;,
                                      font=(&quot;Arial Rounded MT Bold&quot;, 30))
      computer_choice_label.place(x=450, y=310)
  
  
  user_choice_button = Button(window, text=&quot;Click to\nchoose&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 40), bg=&quot;#b6f5f8&quot;,
                              fg=&quot;#f59c97&quot;, command=user_choice)
  user_choice_button.place(x=50, y=300)
  computer_choice_label = Label(window, text=&quot;The computer's\nchoice will be\ndisplayed here&quot;,
                                font=(&quot;Arial Rounded MT Bold&quot;, 30), bg=&quot;#fbfcbc&quot;, fg=&quot;#f59c97&quot;)
  computer_choice_label.place(x=450, y=310)
  start_button = Button(window, text=&quot;START&quot;, font=(&quot;Arial Rounded MT Bold&quot;, 30), bg=&quot;lime&quot;, command=start)
  start_button.place(x=300, y=200)
  
  
  window.mainloop()
  </code></pre>