import random
from tkinter import *
def auswertung(a1,a2,a3,a4,a5):
b1 = 0
b2 = 0
b3 = 0
b4 = 0
b5 = 0
dreier = 0
k = 0
ausgabe = ""
#Sortieren
j = 1
for i in range (1,7):
zaehler = 0
if i == a1:
zaehler = zaehler + 1
if j == 1:
b1 = a1
elif j == 2:
b2 = a1
elif j == 3:
b3 = a1
elif j == 4:
b4 = a1
elif j == 5:
b5 = a1
j = j + 1
if i == a2:
zaehler = zaehler + 1
if j == 1:
b1 = a2
elif j == 2:
b2 = a2
elif j == 3:
b3 = a2
elif j == 4:
b4 = a2
elif j == 5:
b5 = a2
j = j + 1
if i == a3:
zaehler = zaehler + 1
if j == 1:
b1 = a3
elif j == 2:
b2 = a3
elif j == 3:
b3 = a3
elif j == 4:
b4 = a3
elif j == 5:
b5 = a3
j = j + 1
if i == a4:
zaehler = zaehler + 1
if j == 1:
b1 = a4
elif j == 2:
b2 = a4
elif j == 3:
b3 = a4
elif j == 4:
b4 = a4
elif j == 5:
b5 = a4
j = j + 1
if i == a5:
zaehler = zaehler + 1
if j == 1:
b1 = a5
elif j == 2:
b2 = a5
elif j == 3:
b3 = a5
elif j == 4:
b4 = a5
elif j == 5:
b5 = a5
j = j + 1
if zaehler == 5:
ausgabe = ausgabe + "KNIFFEL"# mit " + str(i)
elif zaehler == 4:
ausgabe = ausgabe + "Viererpasch"# mit " + str(i)
elif zaehler == 3:
dreier = 1
k = i
#Prüfung auf Full House
if dreier == 1:
zaehler2 = 0
for i in range(1, 7):
if not i == k:
zaehler = 0
if i == a1:
zaehler = zaehler + 1
if i == a2:
zaehler = zaehler + 1
if i == a3:
zaehler = zaehler + 1
if i == a4:
zaehler = zaehler + 1
if i == a5:
zaehler = zaehler + 1
if zaehler == 2:
ausgabe = ausgabe + "Full House"# mit " + str(i) + " und " + str(k)
zaehler2 = 1
if zaehler2 == 0:
ausgabe = ausgabe + "Dreierpasch"# mit " + str(k)
if b2 == (b1 + 1) and b3 == (b2 + 1) and b4 == (b3 + 1) and b5 == (b4 + 1):
ausgabe = ausgabe + "Große Straße"
else:
if (b2 == (b1 + 1) and b3 == (b2 + 1) and (b4 == (b3 + 1) or b5 == (b3 + 1))) or (b2 == (b1 + 1) and (b3 == (b2 + 1) or b4 == (b2 + 1)) and b5 == (b2 + 2)) or ((b2 == (b1 + 1) or b3 == (b1 + 1)) and b4 == (b1 + 2) and b5 == (b4 + 1)):
ausgabe = ausgabe + "Kleine Straße"
#print(b1, b2, b3, b4, b5, " (sortiert)")
return ausgabe
def zuruecksetzen():
checkbutton0.config(state='active')
checkbutton1.config(state='active')
checkbutton2.config(state='active')
checkbutton3.config(state='active')
checkbutton4.config(state='active')
labelW1.config(text=str(random.randint(1,6)))
labelW2.config(text=str(random.randint(1,6)))
labelW3.config(text=str(random.randint(1,6)))
labelW4.config(text=str(random.randint(1,6)))
labelW5.config(text=str(random.randint(1,6)))
labelWurf.config(text="1. Wurf")
labelAuswertung.config(text=" ")
labelEintragen.config(text=" ")
summieren()
def auswahlClick():
buttonWuerfeln.config(state='active')
def buttonWuerfelnClick():
if wert0.get() == 1:
labelW1.config(text=str(random.randint(1,6)))
else:
checkbutton0.config(state='disabled')
if wert1.get() == 1:
labelW2.config(text=str(random.randint(1,6)))
else:
checkbutton1.config(state='disabled')
if wert2.get() == 1:
labelW3.config(text=str(random.randint(1,6)))
else:
checkbutton2.config(state='disabled')
if wert3.get() == 1:
labelW4.config(text=str(random.randint(1,6)))
else:
checkbutton3.config(state='disabled')
if wert4.get() == 1:
labelW5.config(text=str(random.randint(1,6)))
else:
checkbutton4.config(state='disabled')
checkbutton0.deselect()
checkbutton1.deselect()
checkbutton2.deselect()
checkbutton3.deselect()
checkbutton4.deselect()
buttonWuerfeln.config(state='disabled')
if labelWurf.cget("text")=="1. Wurf":
labelWurf.config(text="2. Wurf")
elif labelWurf.cget("text")=="2. Wurf":
labelWurf.config(text="3. Wurf")
checkbutton0.config(state='disabled')
checkbutton1.config(state='disabled')
checkbutton2.config(state='disabled')
checkbutton3.config(state='disabled')
checkbutton4.config(state='disabled')
labelAuswertung.config(text=auswertung(int(labelW1.cget("text")), int(labelW2.cget("text")), int(labelW3.cget("text")), int(labelW4.cget("text")), int(labelW5.cget("text"))))
def buttonFertigClick():
pass
# Fenster
tkFenster = Tk()
tkFenster.title('Kniffel')
tkFenster.geometry('220x390')
# Frames
frameWuerfel = Frame(master=tkFenster, bg="white")
frameWuerfel.place(x=10, y=10, width=210, height=80)
frameAuswahl = Frame(master=tkFenster, bg="white")
frameAuswahl.place(x=10, y=100, width=210, height=170)
frameAuswertung = Frame(master=tkFenster, bg="white")
frameAuswertung.place(x=10, y=280, width=210, height=100)
# Label
labelWurf = Label (master=frameWuerfel, text="1. Wurf")
labelWurf.place(x=10, y=10, width=100, height=20)
labelW1 = Label(master=frameWuerfel, bg="gray", text=str(random.randint(1,6)))
labelW1.place(x=10, y=40, width=30, height=30)
labelW2 = Label(master=frameWuerfel, bg="gray", text=str(random.randint(1,6)))
labelW2.place(x=50, y=40, width=30, height=30)
labelW3 = Label(master=frameWuerfel, bg="gray", text=str(random.randint(1,6)))
labelW3.place(x=90, y=40, width=30, height=30)
labelW4 = Label(master=frameWuerfel, bg="gray", text=str(random.randint(1,6)))
labelW4.place(x=130, y=40, width=30, height=30)
labelW5 = Label(master=frameWuerfel, bg="gray", text=str(random.randint(1,6)))
labelW5.place(x=170, y=40, width=30, height=30)
labelFrage = Label (master=frameAuswahl, text="Welche Würfel sollen\n neu gewürfelt werden?")
labelFrage.place(x=10, y=10, width=190, height=50)
labelErgebnis = Label(master=frameAuswertung, text="Würfelergebnis:")
labelErgebnis.place(x=10, y=10, width=190, height=20)
labelAuswertung = Label(master=frameAuswertung, text="")
labelAuswertung.place(x=10, y=30, width=190, height=20)
labelEintragen = Label(master=frameAuswertung, text="")
labelEintragen.place(x=10, y=50, width=190, height=40)
# Kontrollvariablen
wert0 = IntVar()
wert1 = IntVar()
wert2 = IntVar()
wert3 = IntVar()
wert4 = IntVar()
# Checkbutton
checkbutton0 = Checkbutton(master=frameAuswahl, bg="white", anchor='w', offvalue=0, onvalue=1, variable=wert0, command=auswahlClick)
checkbutton0.place(x=15, y=65, width=20, height=20)
checkbutton1 = Checkbutton(master=frameAuswahl, bg="white", anchor='w', offvalue=0, onvalue=1, variable=wert1, command=auswahlClick)
checkbutton1.place(x=55, y=65, width=20, height=20)
checkbutton2 = Checkbutton(master=frameAuswahl, bg="white", anchor='w', offvalue=0, onvalue=1, variable=wert2, command=auswahlClick)
checkbutton2.place(x=95, y=65, width=20, height=20)
checkbutton3 = Checkbutton(master=frameAuswahl, bg="white", anchor='w', offvalue=0, onvalue=1, variable=wert3, command=auswahlClick)
checkbutton3.place(x=135, y=65, width=20, height=20)
checkbutton4 = Checkbutton(master=frameAuswahl, bg="white", anchor='w', offvalue=0, onvalue=1, variable=wert4, command=auswahlClick)
checkbutton4.place(x=175, y=65, width=20, height=20)
# Button
buttonWuerfeln = Button (master=frameAuswahl, text="neu würfeln", command=buttonWuerfelnClick, state='disabled')
buttonWuerfeln.place(x=10, y=95, width=190, height=30)
buttonFertig = Button (master=frameAuswahl, text="fertig", command=buttonFertigClick)
buttonFertig.place(x=10, y=130, width=190, height=30)
# Aktivierung des Fensters
tkFenster.mainloop()
So???