Skip to content

Commit 1762985

Browse files
authored
Create Random-Lottery-Generator.py
1 parent 2a1e1fd commit 1762985

1 file changed

Lines changed: 197 additions & 0 deletions

File tree

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import sys
2+
import os
3+
import tkinter as tk
4+
from tkinter import messagebox
5+
import random
6+
7+
# =========================
8+
# THEME
9+
# =========================
10+
APP_BG = "#121212"
11+
PANEL_BG = "#1F1F1F"
12+
BTN_BG = "#2C2C2C"
13+
ACCENT = "#FF6F61"
14+
TEXT_CLR = "#E0E0E0"
15+
SUBTEXT_CLR = "#AAAAAA"
16+
17+
FONT = ("Segoe UI", 11)
18+
19+
# =========================
20+
# RESOURCE PATH
21+
# =========================
22+
def resource_path(file_name):
23+
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
24+
return os.path.join(base_path, file_name)
25+
26+
# =========================
27+
# LOTTERY LOGIC
28+
# =========================
29+
def generate_lottery(min_num, max_num, count):
30+
if count > (max_num - min_num + 1):
31+
raise ValueError("Count exceeds available unique numbers.")
32+
return sorted(random.sample(range(min_num, max_num + 1), count))
33+
34+
# =========================
35+
# APP
36+
# =========================
37+
class LotteryGenerator:
38+
def __init__(self, root):
39+
self.root = root
40+
root.title("MateTools – Random Lottery Generator")
41+
root.geometry("1000x520")
42+
root.configure(bg=APP_BG)
43+
root.resizable(False, False)
44+
45+
# =========================
46+
# LEFT PANEL
47+
# =========================
48+
left = tk.Frame(root, bg=PANEL_BG, width=420)
49+
left.pack(side="left", fill="y")
50+
51+
# =========================
52+
# HEADER
53+
# =========================
54+
header = tk.Frame(left, bg=PANEL_BG)
55+
header.pack(fill="x", padx=16, pady=(18, 10))
56+
57+
tk.Label(
58+
header,
59+
text="MateTools",
60+
bg=PANEL_BG,
61+
fg=ACCENT,
62+
font=("Segoe UI", 20, "bold")
63+
).pack(side="left")
64+
65+
tk.Frame(left, bg=ACCENT, height=2).pack(fill="x", padx=16, pady=(0, 14))
66+
67+
# =========================
68+
# SUB TITLE
69+
# =========================
70+
tk.Label(
71+
left,
72+
text="Random Lottery Generator",
73+
bg=PANEL_BG,
74+
fg=TEXT_CLR,
75+
font=("Segoe UI", 14, "bold")
76+
).pack(anchor="w", padx=16, pady=(0, 2))
77+
78+
tk.Label(
79+
left,
80+
text="Generate unique random lottery numbers",
81+
bg=PANEL_BG,
82+
fg=SUBTEXT_CLR,
83+
font=("Segoe UI", 10)
84+
).pack(anchor="w", padx=16, pady=(0, 16))
85+
86+
tk.Frame(left, bg=BTN_BG, height=1).pack(fill="x", padx=16, pady=(0, 16))
87+
88+
# =========================
89+
# INPUTS
90+
# =========================
91+
def labeled_entry(label):
92+
tk.Label(
93+
left,
94+
text=label,
95+
bg=PANEL_BG,
96+
fg=TEXT_CLR,
97+
font=("Segoe UI", 11, "bold")
98+
).pack(anchor="w", padx=16, pady=(10, 4))
99+
e = tk.Entry(
100+
left,
101+
bg=BTN_BG,
102+
fg="white",
103+
font=FONT,
104+
relief="flat"
105+
)
106+
e.pack(fill="x", padx=16)
107+
return e
108+
109+
self.min_entry = labeled_entry("Minimum Number")
110+
self.min_entry.insert(0, "1")
111+
112+
self.max_entry = labeled_entry("Maximum Number")
113+
self.max_entry.insert(0, "49")
114+
115+
self.count_entry = labeled_entry("Numbers to Draw")
116+
self.count_entry.insert(0, "6")
117+
118+
# =========================
119+
# BUTTONS
120+
# =========================
121+
btn_frame = tk.Frame(left, bg=PANEL_BG)
122+
btn_frame.pack(fill="x", padx=16, pady=20)
123+
124+
def make_btn(text, cmd, color=BTN_BG):
125+
return tk.Button(
126+
btn_frame,
127+
text=text,
128+
command=cmd,
129+
bg=color,
130+
fg="white",
131+
font=("Segoe UI", 11, "bold"),
132+
relief="flat",
133+
height=2,
134+
width=18
135+
)
136+
137+
make_btn("Generate", self.generate).pack(side="left", expand=True, padx=4)
138+
make_btn("About", self.show_about, ACCENT).pack(side="left", expand=True, padx=4)
139+
140+
# =========================
141+
# RIGHT PANEL
142+
# =========================
143+
right = tk.Frame(root, bg=APP_BG)
144+
right.pack(side="right", fill="both", expand=True)
145+
146+
stats_card = tk.Frame(right, bg=PANEL_BG)
147+
stats_card.pack(padx=30, pady=40, fill="both", expand=True)
148+
149+
tk.Label(
150+
stats_card,
151+
text="Generated Numbers",
152+
bg=PANEL_BG,
153+
fg=TEXT_CLR,
154+
font=("Segoe UI", 14, "bold")
155+
).pack(pady=(20, 10))
156+
157+
self.result_label = tk.Label(
158+
stats_card,
159+
text="—",
160+
bg=PANEL_BG,
161+
fg="white",
162+
font=("Segoe UI", 22, "bold")
163+
)
164+
self.result_label.pack(pady=30)
165+
166+
# =========================
167+
# METHODS
168+
# =========================
169+
def generate(self):
170+
try:
171+
min_n = int(self.min_entry.get())
172+
max_n = int(self.max_entry.get())
173+
count = int(self.count_entry.get())
174+
175+
numbers = generate_lottery(min_n, max_n, count)
176+
self.result_label.config(text=" ".join(map(str, numbers)))
177+
178+
except Exception as e:
179+
messagebox.showerror("Error", str(e))
180+
181+
def show_about(self):
182+
messagebox.showinfo(
183+
"About",
184+
"MateTools – Random Lottery Generator\n\n"
185+
"• Unique random numbers\n"
186+
"• Custom ranges & counts\n"
187+
"• Clean, modern UI\n\n"
188+
"Built by MateTools"
189+
)
190+
191+
# =========================
192+
# RUN
193+
# =========================
194+
if __name__ == "__main__":
195+
root = tk.Tk()
196+
LotteryGenerator(root)
197+
root.mainloop()

0 commit comments

Comments
 (0)