-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottoNumberPicker.py
More file actions
185 lines (152 loc) · 5.57 KB
/
LottoNumberPicker.py
File metadata and controls
185 lines (152 loc) · 5.57 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"""Multi-Lottery Number Picker - Supports Powerball and Mega Millions."""
from tkinter import Tk, Label, Button, DISABLED, NORMAL, StringVar, OptionMenu, Frame
from random import sample, randint
from pathlib import Path
# Lottery configurations
LOTTERY_TYPES = {
'Powerball': {
'white_balls': 5,
'white_range': (1, 69),
'bonus_balls': 1,
'bonus_range': (1, 26),
'bonus_name': 'Powerball',
'bonus_color': '#E63946' # Red
},
'Mega Millions': {
'white_balls': 5,
'white_range': (1, 70),
'bonus_balls': 1,
'bonus_range': (1, 25),
'bonus_name': 'Mega Ball',
'bonus_color': '#FFD700' # Gold
}
}
DEFAULT_TEXT = '...'
class LottoPickerApp:
"""Main application class for the Multi-Lottery Number Picker."""
def __init__(self, root):
self.root = root
self.root.title('Multi-Lottery Number Picker')
self.root.resizable(0, 0)
self.current_lottery = StringVar(value='Powerball')
self.white_labels = []
self.bonus_label = None
self._setup_widgets()
self._setup_layout()
def _setup_widgets(self):
"""Create and configure all widgets."""
# Lottery type selector frame
self.lottery_frame = Frame(self.root)
self.lottery_label = Label(
self.lottery_frame,
text="Select Lottery:",
font=('Arial', 10, 'bold')
)
self.lottery_menu = OptionMenu(
self.lottery_frame,
self.current_lottery,
*LOTTERY_TYPES.keys(),
command=self.on_lottery_change
)
self.lottery_menu.config(width=15)
# Create 5 white ball labels
for _ in range(5):
label = Label(
self.root,
relief='groove',
width=4,
height=2,
text=DEFAULT_TEXT,
font=('Arial', 14, 'bold'),
bg='white'
)
self.white_labels.append(label)
# Create bonus ball label (highlighted)
self.bonus_label = Label(
self.root,
relief='groove',
width=4,
height=2,
text=DEFAULT_TEXT,
font=('Arial', 14, 'bold'),
bg=LOTTERY_TYPES['Powerball']['bonus_color'],
fg='white'
)
# Create bonus ball name label
self.bonus_name_label = Label(
self.root,
text=LOTTERY_TYPES['Powerball']['bonus_name'],
font=('Arial', 9)
)
# Create buttons
self.get_btn = Button(
self.root,
text='Get My Lucky Numbers',
command=self.pick_numbers,
font=('Arial', 10),
padx=10,
pady=5
)
self.reset_btn = Button(
self.root,
text='Reset',
command=self.reset,
state=DISABLED,
font=('Arial', 10),
padx=10,
pady=5
)
def _setup_layout(self):
"""Arrange widgets using grid layout."""
# Lottery selector at top
self.lottery_frame.grid(row=0, column=0, columnspan=6, pady=(10, 15))
self.lottery_label.pack(side='left', padx=(0, 10))
self.lottery_menu.pack(side='left')
# White ball labels
for i, label in enumerate(self.white_labels):
label.grid(row=1, column=i, padx=5, pady=5)
# Bonus ball label (highlighted)
self.bonus_label.grid(row=1, column=5, padx=(15, 5), pady=5)
# Bonus ball name
self.bonus_name_label.grid(row=2, column=5, pady=(0, 10))
# Buttons
self.get_btn.grid(row=3, column=0, columnspan=4, pady=10, padx=5, sticky='ew')
self.reset_btn.grid(row=3, column=4, columnspan=2, pady=10, padx=5, sticky='ew')
def on_lottery_change(self, selection):
"""Handle lottery type change."""
config = LOTTERY_TYPES[selection]
# Update bonus ball color and name
self.bonus_label.configure(bg=config['bonus_color'])
self.bonus_name_label.configure(text=config['bonus_name'])
# Reset the display
self.reset()
def pick_numbers(self):
"""Generate and display random lottery numbers."""
config = LOTTERY_TYPES[self.current_lottery.get()]
# Generate white balls (sorted)
white_min, white_max = config['white_range']
white_nums = sorted(sample(range(white_min, white_max + 1), config['white_balls']))
# Display white balls
for label, num in zip(self.white_labels, white_nums):
label.configure(text=str(num))
# Generate and display bonus ball
bonus_min, bonus_max = config['bonus_range']
bonus_num = randint(bonus_min, bonus_max)
self.bonus_label.configure(text=str(bonus_num))
# Update button states
self.get_btn.configure(state=DISABLED)
self.reset_btn.configure(state=NORMAL)
def reset(self):
"""Reset all labels to default state."""
for label in self.white_labels:
label.configure(text=DEFAULT_TEXT)
self.bonus_label.configure(text=DEFAULT_TEXT)
self.get_btn.configure(state=NORMAL)
self.reset_btn.configure(state=DISABLED)
def main():
"""Main entry point for the application."""
root = Tk()
app = LottoPickerApp(root)
root.mainloop()
if __name__ == '__main__':
main()