Code: Alles auswählen
import random
from tkinter import *
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():
pass
def buttonWuerfelnClick():
pass
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()
wie kann ich folgendes bei der Oberfläche ausführen, damit das Programm auch läuft
- Der Spieler wählt die Checkbuttons aller Würfel aus, mit denen er noch einmal würfeln möchte. Dadurch wird der Button "neu würfeln" aktiviert.
- Verwendet der Spieler den Button "neu würfeln",
- verändert sich das Label ganz oben zu "2. Wurf" (bzw. "3. Wurf").
- erscheinen für die ausgewählte Würfel neue Zufallszahlen, wird der Button "neu würfeln" wieder deaktivert und können im nächsten Wurf nur noch die Würfel ausgewählt werden, die im vorherigen Wurf neu gewürfelt wurden.
- Nach dem dritten Wurf können weder die Checkbuttons noch "neu würfeln" angeklickt werden.
- Der Button "fertig" und das untere Label bleiben erstmal ohne Funktion.