Skip to content

Commit f9869cf

Browse files
authored
Improve game scheduling interface and validation
Refactor game scheduling UI and add validation for team selection.
1 parent fd492ae commit f9869cf

1 file changed

Lines changed: 36 additions & 49 deletions

File tree

Droplistmenu/GamesCalender.py

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,49 @@
1-
from tkinter import *
2-
from tkcalendar import Calendar
31
import tkinter as tk
2+
from tkinter import messagebox
3+
from tkcalendar import Calendar
44

5-
6-
window = tk.Tk()
7-
8-
# Adjust size
9-
window.geometry("600x500")
10-
11-
gameList = ["Game List:"]
12-
13-
14-
# Change the label text
155
def show():
16-
game = selected1.get() + " vs " + selected2.get() + " on " + cal.get_date()
17-
gameList.append(game)
18-
# print(gameList)
19-
gameListshow = "\n".join(gameList)
20-
# print(gameList)
21-
label.config(text=gameListshow)
6+
visitor = selected1.get()
7+
home = selected2.get()
8+
9+
# Validation: Check if teams are the same
10+
if visitor == home:
11+
messagebox.showwarning("Input Error", "Visitor and Home teams cannot be the same!")
12+
return
13+
14+
game = f"{visitor} vs {home} on {cal.get_date()}"
15+
16+
# Update the Text widget
17+
display_area.config(state=tk.NORMAL) # Enable editing
18+
display_area.insert(tk.END, game + "\n")
19+
display_area.config(state=tk.DISABLED) # Make read-only
20+
21+
# Optional: Clear dropdowns or reset
22+
selected1.set("Team 1")
23+
selected2.set("Team 2")
2224

25+
window = tk.Tk()
26+
window.title("Game Scheduler")
27+
window.geometry("600x550")
2328

24-
# Dropdown menu options
2529
options = ["Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6"]
30+
selected1 = tk.StringVar(value="Team 1")
31+
selected2 = tk.StringVar(value="Team 2")
2632

27-
# datatype of menu text
28-
selected1 = StringVar()
29-
selected2 = StringVar()
30-
31-
# initial menu text
32-
selected1.set("Team 1")
33-
selected2.set("Team 2")
34-
35-
# Create Dropdown menu
36-
L1 = Label(window, text="Visitor")
37-
L1.place(x=40, y=35)
38-
drop1 = OptionMenu(window, selected1, *options)
39-
drop1.place(x=100, y=30)
40-
41-
L2 = Label(window, text="VS")
42-
L2.place(x=100, y=80)
43-
44-
L3 = Label(window, text="Home")
45-
L3.place(x=40, y=115)
46-
drop2 = OptionMenu(window, selected2, *options)
47-
drop2.place(x=100, y=110)
48-
49-
# Add Calendar
50-
cal = Calendar(window, selectmode="day", year=2022, month=12, day=1)
33+
# UI Layout using Grid for better alignment
34+
tk.Label(window, text="Visitor:").grid(row=0, column=0, padx=10, pady=10)
35+
tk.OptionMenu(window, selected1, *options).grid(row=0, column=1)
5136

52-
cal.place(x=300, y=20)
37+
tk.Label(window, text="Home:").grid(row=1, column=0, padx=10, pady=10)
38+
tk.OptionMenu(window, selected2, *options).grid(row=1, column=1)
5339

40+
cal = Calendar(window, selectmode="day", year=2026, month=6, day=2)
41+
cal.grid(row=0, column=2, rowspan=2, padx=20)
5442

55-
# Create button, it will change label text
56-
button = Button(window, text="Add to calendar", command=show).place(x=100, y=200)
43+
tk.Button(window, text="Add to Schedule", command=show).grid(row=2, column=0, columnspan=2, pady=20)
5744

58-
# Create Label
59-
label = Label(window, text=" ")
60-
label.place(x=150, y=250)
45+
# Scrollable display area
46+
display_area = tk.Text(window, height=10, width=50, state=tk.DISABLED)
47+
display_area.grid(row=3, column=0, columnspan=3, padx=10)
6148

6249
window.mainloop()

0 commit comments

Comments
 (0)