STP/stp.py
2023-08-07 10:07:40 +02:00

59 lines
2.7 KiB
Python

from tkinter import *
import random
root = Tk()
root.geometry("900x500")
stp = ["s", "r", "p"]
punkte1 = 0
punkte2 = 0
def ok():
s1 = s1_wert.get()
com = (random.choice(stp))
if s1 == com:
Label(root, text=" Unentschieden ",font=("times",25)).grid(row=6, column=1)
elif s1 == "s" and com == "p" or s1 == "p" and com == "r" or s1 == "r" and com == "s":
global punkte1
punkte1 += 1
Label(root, text=" Spieler 1 Gewinnt ", font=("times",25)).grid(row=6, column=1)
Label(root, text="Punkte: ", font=("times",25)).grid(row=8)
Label(root, text=punkte1, font=("times",25)).grid(row=9)
if s1 == "s" and com == "p":
Label(root,text=" wählt Schere ", bg="green", font=("times", 25)).grid(row=6)
Label(root,text=" wählt Papier ", bg="red", font=("times", 25)).grid(row=6, column=2)
elif s1 == "p" and com == "r":
Label(root,text=" wählt Papier ", bg="green", font=("times", 25)).grid(row=6)
Label(root,text=" wählt Stein ", bg="red", font=("times", 25)).grid(row=6, column=2)
elif s1 == "r" and com == "s":
Label(root,text=" wählt Stein ", bg="green", font=("times", 25)).grid(row=6)
Label(root,text=" wählt Schere ", bg="red", font=("times", 25)).grid(row=6, column=2)
else:
global punkte2
punkte2 += 1
Label(root, text="Computer Gewinnt", font=("times", 25)).grid(row=6, column=1)
Label(root, text="Punkte:", font=("times",25)).grid(row=8, column=2)
Label(root, text=punkte2, font=("times",25)).grid(row=9, column=2)
if com == "r" and s1 == "s":
Label(root,text=" wählt Schere ", bg="red", font=("times", 25)).grid(row=6)
Label(root,text=" wählt Stein ", bg="green", font=("times", 25)).grid(row=6, column=2)
elif com == "s" and s1 == "p":
Label(root,text=" wählt Papier ", bg="red", font=("times", 25)).grid(row=6)
Label(root,text=" wählt Schere ", bg="green", font=("times", 25)).grid(row=6, column=2)
elif com == "p" and s1 == "r":
Label(root,text=" wählt Stein ", bg="red", font=("times", 25)).grid(row=6)
Label(root,text=" wählt Papier ", bg="green", font=("times", 25)).grid(row=6, column=2)
Label(root, text="S = Schere, R = Stein, P = Papier ", font=("times",25,)).grid(column=1)
Label(root, text="Spieler 1", font=("times", 25)).grid(row=1)
Label(root, text="Computer", font=("times", 25)).grid(row=1, column=2)
s1_wert = Entry(root,font=(28))
s1_wert.grid(row=3)
Button(root, text="Wählen", command=ok, font=("times", 30)).grid(row=2, column=1)
root.mainloop()