0

I have a Rock Paper Scissors game and on labels that state if you won or not, there are parts of other letters (look at screenshot below). Is there a way to fix this within my code or is it a bug within tkinter.

https://i.stack.imgur.com/znuxS.png

Here is my code:

from tkinter import *
import random
root = Tk()
rps = ['rock', 'paper', 'scissors']

def rock():
    rock.comp_choice = random.choice(rps)
    YUH = Label(root, text=rock.comp_choice)
    YUH.grid(column=2, row=1, padx=10, pady=10)
    r_results()

def paper():
    paper.comp_choice = random.choice(rps)
    YUH = Label(root, text=paper.comp_choice)
    YUH.grid(column=2, row=1, padx=10, pady=10)
    p_results()

def scissors():
    scissors.comp_choice = random.choice(rps)
    YUH = Label(root, text=scissors.comp_choice)
    YUH.grid(column=2, row=1, padx=10, pady=10)
    s_results()

def r_results():
    if paper.comp_choice == 'paper':
        loose = Label(root, text='Loose')
        loose.grid(column=2, row=2, padx=10, pady=10)
    if paper.comp_choice == 'scissors':
        win = Label(root, text='Win')
        win.grid(column=2, row=2, padx=10, pady=10)
    if paper.comp_choice == 'rock':
        tie = Label(root, text='Tie')
        tie.grid(column=2, row=2, padx=10, pady=10)

def p_results():
    if paper.comp_choice == 'paper':
        loose = Label(root, text='Tie')
        loose.grid(column=2, row=2, padx=10, pady=10)
    if paper.comp_choice == 'scissors':
        win = Label(root, text='Loose')
        win.grid(column=2, row=2, padx=10, pady=10)
    if paper.comp_choice == 'rock':
        tie = Label(root, text='Win')
        tie.grid(column=2, row=2, padx=10, pady=10)

def s_results():
    if scissors.comp_choice == 'paper':
        loose = Label(root, text='Win')
        loose.grid(column=2, row=2, padx=10, pady=10)
    if scissors.comp_choice == 'scissors':
        win = Label(root, text='Tie')
        win.grid(column=2, row=2, padx=10, pady=10)
    if scissors.comp_choice == 'rock':
        tie = Label(root, text='Loose')
        tie.grid(column=2, row=2, padx=10, pady=10)

rock = Button(root, text="rock", command=rock)
paper = Button(root, text="paper", command=paper)
scissors = Button(root, text="scissors", command=scissors) 
rock.grid(column=1, row=0, padx=10, pady=10)
paper.grid(column=2, row=0, padx=10, pady=10)
scissors.grid(column=3, row=0, padx=10, pady=10)

mainloop()
Jay Martin
  • 21
  • 2
  • 1
    if weird text like this appears, try to reload the UI element you write the text to (before you write the text to it) - most times that works (with any UI) ^^ – finnmglas May 22 '20 at 04:22
  • 2
    It is because you create new label every time one of the paper/rock/scissors function is called. Better create the label first, then update its text inside those functions. – acw1668 May 22 '20 at 04:31
  • Does this answer your question? [making-python-tkinter-label-widget-update](https://stackoverflow.com/questions/1918005) – stovfl May 22 '20 at 10:09

0 Answers0