-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinFlipGUI.py
More file actions
64 lines (51 loc) · 1.84 KB
/
coinFlipGUI.py
File metadata and controls
64 lines (51 loc) · 1.84 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Jesse A. Jones
#Version: 2022-12-28.1
from random import randint
from tkinter import *
from time import sleep
#Contains the members and methods necessary
# to yield the result of a coin flip,
# being Heads or Tails.
class CoinFlip(object):
def __init__(self, window = None):
self.window = window
#Contains the quit button and flip button.
self.frameTop = Frame(self.window)
self.frameTop.pack(side = TOP)
self.quitButton = Button(self.frameTop, text = "Quit",
font = "Ariel 20", command = self.quitButtonAction)
self.quitButton.pack(side = RIGHT)
self.flipper = Button(self.frameTop, text = "Flip Coin",
font = "Ariel 20", command = self.coinUpdate)
self.flipper.pack(side = LEFT)
#Contains the output from a given flip.
self.frameBottom = Frame(self.window)
self.frameBottom.pack(side = BOTTOM)
#Output of flip.
self.message = Entry(self.frameBottom, font = "Times 30", justify = CENTER)
self.message.pack(side = TOP)
#Quits the program.
def quitButtonAction(self):
self.window.destroy()
#Flips the coin and displays the result to the user.
def coinUpdate(self):
flip = self.flipCoin()
#Displays progress message before displaying output to user.
self.message.delete(0, "end")
self.message.insert(0, "Flipping...")
self.message.update()
sleep(1)
self.message.delete(0, "end")
self.message.insert(0, flip)
#Uses random's randint method to 'randomly'
# choose between a head or tail side.
def flipCoin(self):
posArr = ["Heads", "Tails"]
return posArr[randint(0, 1)]
def main():
root = Tk()
root.title("Coin Flipper")
coin = CoinFlip(root)
root.mainloop()
if __name__ == "__main__":
main()