0

I've set a function to insert the choice of play into the entry box but I am having trouble with using the PLAY button to get that choice and then use the if/else statement to declare the winner? It inserts the choice but when i press play, it just deletes the choice and nothing else is inserted. Any Ideas? Thank you very much! This is my code so far and any tips would be great if possible. If not, just the answer to the question would be perfect!

from tkinter import *
from PIL import ImageTk, Image
import tkinter.font as font
from random import randint
#Fix Frame

root = Tk()

root.title('Rock Paper Scissors')

root.configure(background ='peach puff' )

def clicked(type):

    global current
    current = e.get()
    global t
    global computer
    global player
    e.delete(0, END)
    e.insert(0, str(current) + type)

def play():

    global t
    global computer
    global player
    global current
    e.delete(0, END)
    if player == computer:
        e.insert("Tie!")
    elif player == 'Paper':
        if computer == 'Scissors':
            e.insert(0, 'You Lose! ' + computer + ' cuts' + str(current))
        else:
            e.insert(0, 'You Win! ' + str(current) + ' covers ' + computer)
    elif player == 'Rock':
        if computer == 'Paper':
            e.insert(0,'You Lose! ' + computer + ' covers ' + str(current))
        else:
            e.insert(0, 'You Win! ' + str(current) + ' smashes ' + computer)
    elif player == 'Scissors':
        if computer == 'Rock':
            e.insert(0, 'You Lose! ' + computer + 'smashes' + str(current))
        else:
            e.insert(0, 'You Win! ' + str(current) + 'cuts' + computer)

rock_butt = Button(root, image=rock_photo,command=lambda:clicked(t[0]))

paper_butt = Button(root, image=paper_photo ,command=lambda:clicked(t[1]))

scissors_butt = Button(root, image=scissor_photo ,command=lambda: clicked(t[2]))

play_butt = Button(root, text= 'Play', padx=60, pady=20, command=play)

quit_butt = Button(root, text= 'Quit Program',bg='light sea green', padx= 40, pady=40, fg='OliveDrab1', command = root.quit)
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
  • You might want to look into the Tkinter StringVar(). A StringVar() object can be easily passed to a label widget's textvariable attribute and allowing modification of the text in the label by controlling what is passed to the variable. Lot easier than inserts and deletes. This is probably a useful reference https://stackoverflow.com/questions/2603169/update-tkinter-label-from-variable . Also I would highly recommend using a class for your application. Would prevent the need to declare everything as global. – Sharpfawkes Mar 08 '21 at 17:33
  • Welcome to stackoverflow, you should have a look at the [How to ask page](https://stackoverflow.com/help/how-to-ask) in the help center, especially the part about the title :) (hint: yours is way too long and not very informative, it should be the start of the body of the question, not the title) – j_4321 Mar 08 '21 at 21:52
  • Thank you for the answers and help! Really appreciate it! – CSJimBob Mar 09 '21 at 03:23

0 Answers0