-
Notifications
You must be signed in to change notification settings - Fork 0
/
chuckgui.py
46 lines (39 loc) · 1.38 KB
/
chuckgui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# chuckgui.py
from dicegui import DiceGUI
from tkinter import *
class ChuckALuckGUI(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
parent.geometry("500x300")
parent.title("Chuck-A-Luck")
self.dice = DiceGUI(3, self)
self.dice.pack(fill="y", expand=True)
self.score = 0
self.makecontrols()
self.makescore()
self.pack(fill="y", expand=True)
def makecontrols(self):
self.choice = IntVar()
controlframe = Frame(self)
for i in range(1, 7):
Radiobutton(controlframe, text=str(i), value=i,
variable=self.choice).pack(side="left")
Label(controlframe, width=5).pack(side="left")
Button(controlframe, width=10, text="Roll",
command=self.roll).pack(side="left")
controlframe.pack()
def makescore(self):
self.scorestr = StringVar()
Label(self, textvariable=self.scorestr,
font=("Helvetica", 24)).pack(fill="y", expand=True)
self.updatescore()
def roll(self):
self.dice.rollall()
matches = self.dice.count(self.choice.get())
self.score += matches if matches > 0 else -1
self.updatescore()
def updatescore(self):
self.scorestr.set("Score: " + str(self.score))
root = Tk()
app = ChuckALuckGUI(root)
root.mainloop()