-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
133 lines (118 loc) · 3.45 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /usr/bin/env python
import random
import Tkinter as tk
import array as ar
root = tk.Tk()
root.title("RPG Dice Roller")
textframe = tk.Frame(root)
listframe = tk.Frame(root)
amountAMT = tk.Entry(textframe, width=5)
amountMOD = tk.Entry(textframe, width=5)
amountINPT = int()
def D2():
dtype = 2
Roll(GetAMT(), dtype)
def D3():
dtype = 3
Roll(GetAMT(), dtype)
def D4():
dtype = 4
Roll(GetAMT(), dtype)
def D6():
dtype = 6
Roll(GetAMT(), dtype)
def D8():
dtype = 8
Roll(GetAMT(), dtype)
def D10():
dtype = 10
Roll(GetAMT(), dtype)
def D12():
dtype = 12
Roll(GetAMT(), dtype)
def D20():
dtype = 20
Roll(GetAMT(), dtype)
def D100():
dtype = 100
Roll(GetAMT(), dtype)
def GetAMT():
try:
text_contents = int(amountAMT.get())
except ValueError:
text_contents=1
if not amountAMT.get():
text_contents=1
amountINPT = text_contents
return amountINPT
def GetMOD():
try:
text_contentsM = int(amountMOD.get())
except ValueError:
text_contentsM=1
if not amountMOD.get():
text_contentsM=0
amountMODINPT = text_contentsM
return amountMODINPT
def Roll(inpt, dtype):
textBox.delete(1.0, tk.END)
amountpass = 0
total = 0
dicearray = ar.array('i')
while amountpass < inpt:
x = random.randint(1, dtype)
dicearray.insert(amountpass, x)
amountpass = amountpass + 1
textBox.insert(tk.INSERT,'Roll ')
textBox.insert(tk.INSERT,amountpass)
textBox.insert(tk.INSERT, ': ')
textBox.insert(tk.INSERT,x)
textBox.insert(tk.INSERT,'\n')
for i in dicearray:
total = total + i
totalRoll = total + GetMOD()
if (totalRoll <= 0):
totalRoll = 0
textBox.insert(tk.INSERT, 'Total:')
textBox.insert(tk.INSERT, total)
if (GetMOD() >= 0):
textBox.insert(tk.INSERT, ' + ')
if (GetMOD() < 0):
textBox.insert(tk.INSERT, ' - ')
textBox.insert(tk.INSERT, abs(GetMOD()))
textBox.insert(tk.INSERT, ' = ')
textBox.insert(tk.INSERT, totalRoll)
buttonD2 = tk.Button(textframe, text ="D2", command = D2)
buttonD3 = tk.Button(textframe, text ="D3", command = D3)
buttonD4 = tk.Button(textframe, text ="D4", command = D4)
buttonD6 = tk.Button(textframe, text ="D6", command = D6)
buttonD8 = tk.Button(textframe, text ="D8", command = D8)
buttonD10 = tk.Button(textframe, text ="D10", command = D10)
buttonD12 = tk.Button(textframe, text ="D12", command = D12)
buttonD20 = tk.Button(textframe, text ="D20", command = D20)
buttonD100 = tk.Button(textframe, text ="D100", command = D100)
scrollbar = tk.Scrollbar(listframe, orient=tk.VERTICAL)
textBox = tk.Text(listframe, yscrollcommand=scrollbar.set)
scrollbar.configure(command=textBox.yview)
lblAMT = tk.Label(textframe, text="Amount:")
lblMOD = tk.Label(textframe, text="Mod:")
lblMODpn = tk.Label(textframe, text = "(+/-)")
lblAMT.pack(side=tk.LEFT)
amountAMT.pack(side=tk.LEFT, fill=tk.X)
buttonD2.pack(side=tk.LEFT)
buttonD3.pack(side=tk.LEFT)
buttonD4.pack(side=tk.LEFT)
buttonD6.pack(side=tk.LEFT)
buttonD8.pack(side=tk.LEFT)
buttonD10.pack(side=tk.LEFT)
buttonD12.pack(side=tk.LEFT)
buttonD20.pack(side=tk.LEFT)
buttonD100.pack(side=tk.LEFT)
lblMOD.pack(side=tk.LEFT)
amountMOD.pack(side=tk.LEFT, fill=tk.X)
lblMODpn.pack(side=tk.LEFT)
textBox.pack(side=tk.LEFT, expand=1)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
textframe.pack(fill=tk.BOTH)
listframe.pack(fill=tk.BOTH, expand=1)
root.mainloop()