Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- SCOREBOARD Designed by Caleb Boese & Stuart Plunkett
- for Andrew Huddleston
- SCADA Lab #7
- """
- import csv
- from tkinter import *
- from PIL import Image, ImageTk
- font_style_1 = ('Helvetica', 10)
- font_style_2 = ('Helvetica', 20)
- font_style_3 = ('Helvetica', 30)
- # Scoreboard
- root = Tk() # Instantiate the main scoreboard window
- root.title("Scoreboard")
- root["bg"] = "#4B7D0F"
- # =============================== #
- class Game:
- """
- Game object, contains all information for a game to be displayed on the scoreboard, as well as functionality for
- committing the events into a CSV file to track.
- """
- def __init__(self, home_team, away_team):
- self.home_team = home_team # "ottawa" "toronto" etc
- self.away_team = away_team
- self.goals = [] # container for goals
- self.penalties = [] # container for penalties
- self.home_team_shots = IntVar(root, 0) # IntVar to allow updating live with Tk
- self.away_team_shots = IntVar(root, 0) # IntVar to allow updating live with Tk
- self.time_elapsed = 0 # time since period start
- self.current_period = IntVar(root, 1) # current period
- self.current_home_goals = IntVar(root, 0)
- self.current_away_goals = IntVar(root, 0)
- self.timer = StringVar(root)
- self.set_game_time(0)
- self.file_id = 0
- def goal(self, team, period, game_time, scorer, assist1, assist2):
- self.goals.append([team, period, game_time, scorer, assist1, assist2])
- def penalty(self, team, period, game_time, player, infraction):
- self.penalties.append([team, period, game_time, player, infraction])
- def set_game_time(self, value):
- minutes = int((1200 - value) / 60)
- seconds = int((1200 - value) % 60)
- self.timer.set("{:d}:{:02d}".format(minutes, seconds))
- def return_total_goals(self, team):
- i = 0
- for goal in self.goals:
- if goal[0] == team:
- i += 1
- def force_game_time(self, value):
- time_value = value.get().split(':')
- minutes = int(time_value[0])
- seconds = int(time_value[1])
- print("Forcing Game time to " + str(minutes) + " minutes and " + str(seconds) + " seconds")
- total_time_elapsed_in_seconds = (minutes * 60) + seconds
- print("Total Time in S: " + str(1200 - total_time_elapsed_in_seconds))
- self.time_elapsed = 1200 - total_time_elapsed_in_seconds
- self.set_game_time(self.time_elapsed)
- def return_home_goals(self):
- self.current_home_goals.set(self.return_total_goals(self.home_team))
- def return_away_goals(self):
- self.current_away_goals.set(self.return_total_goals(self.away_team))
- def add_home_shot(self):
- self.home_team_shots.set(self.home_team_shots.get() + 1)
- print("home shots increased to ")
- print(self.home_team_shots.get())
- def add_away_shot(self):
- self.away_team_shots.set(self.away_team_shots.get() + 1)
- print("away shots increased to ")
- print(self.away_team_shots.get())
- def power_play(self):
- pass # to be implemented once the timing module is finished
- def force_period(self, new_period):
- self.current_period.set(new_period)
- period_label_string.set(self.current_period.get())
- print("forcing period to ")
- print(self.current_period.get())
- def play(self):
- pass
- def stop(self):
- pass
- def assign_goal(self):
- current_game.goal(goal_assign_team_select_value.get(), goal_assign_period_value,
- game_time_goal_assign_entry_value.get(), goal_assign_player_entry_value.get(),
- assist1_assign_player_entry_value.get(), assist2_assign_player_entry_value.get())
- print(current_game.goals)
- goal_assign_window.withdraw()
- def assign_penalty(self):
- current_game.penalty(goal_assign_team_select_value.get(), goal_assign_period_value,
- game_time_goal_assign_entry_value.get(), penalty_assign_player_entry_value.get(),
- type_of_penalty_assign_entry_value.get())
- print(current_game.penalties)
- penalty_assign_window.withdraw()
- def commit_to_csv(self):
- self.file_id += 1
- filename = "Game #" + str(self.file_id) + ".csv"
- with open(filename, 'w', newline='') as csv_file:
- file_writer = csv.writer(csv_file, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
- for goal in self.goals:
- goal.insert(0, "goal")
- file_writer.writerow(goal)
- for penalty in self.penalties:
- penalty.insert(0, "penalty")
- file_writer.writerow(penalty)
- # =============================== #
- current_game = Game("ottawa", "toronto")
- # =============================== #
- # Control Window
- ctrl = Toplevel() # Instantiate the control window
- ctrl.title("Controls")
- # Menu for Control Window
- ctrl_menu = Menu(ctrl)
- ctrl_menu.add_command(label="New", command=lambda: current_game.__init__("ottawa", "toronto"))
- ctrl_menu.add_command(label="Save to CSV", command=lambda: current_game.commit_to_csv())
- ctrl_menu.add_command(label="Quit", command=root.quit)
- ctrl.config(menu=ctrl_menu)
- force_game_time_label = Label(ctrl, text='Force Game Time: ', font=font_style_1)
- force_game_time_label.grid(row=0, column=0)
- force_game_time_entry_value = StringVar()
- force_game_time_entry = Entry(ctrl, width=5, textvariable=force_game_time_entry_value)
- force_game_time_entry.grid(row=0, column=1)
- force_game_time_confirm = Button(ctrl, text='OK',
- command=lambda: current_game.force_game_time(force_game_time_entry_value))
- force_game_time_confirm.grid(row=0, column=2)
- force_period_label = Label(ctrl, text='Force Period: ', font=font_style_1)
- force_period_label.grid(row=1, column=0, rowspan=3)
- force_period_value = 1
- force_period_one_radio = Radiobutton(ctrl, text="1", variable=force_period_value, value=1)
- force_period_one_radio.grid(row=1, column=1)
- force_period_one_radio = Radiobutton(ctrl, text="2", variable=force_period_value, value=2)
- force_period_one_radio.grid(row=2, column=1)
- force_period_one_radio = Radiobutton(ctrl, text="3", variable=force_period_value, value=3)
- force_period_one_radio.grid(row=3, column=1)
- force_period_confirm = Button(ctrl, text="OK", command=lambda: current_game.force_period(force_period_value))
- force_period_confirm.grid(row=2, column=2)
- add_away_shot_button = Button(ctrl, text='Add Away Shot', font=font_style_1,
- command=lambda: current_game.add_away_shot())
- add_away_shot_button.grid(row=4, column=0)
- add_home_shot_button = Button(ctrl, text='Add Home Shot', font=font_style_1,
- command=lambda: current_game.add_home_shot())
- add_home_shot_button.grid(row=4, column=2)
- add_goal_button = Button(ctrl, text='Goal', font=font_style_1, command=lambda: goal_assign_window.deiconify())
- add_goal_button.grid(row=5, column=0)
- add_penalty_button = Button(ctrl, text='Penalty', font=font_style_1, command=lambda: penalty_assign_window.deiconify())
- add_penalty_button.grid(row=5, column=2)
- play_button = Button(ctrl, text='PLAY', font=font_style_2, command=lambda: current_game.play())
- play_button.grid(row=6, column=0)
- stop_button = Button(ctrl, text='STOP', font=font_style_2, command=lambda: current_game.stop())
- stop_button.grid(row=6, column=2)
- # =============================== #
- # Home/Away Team Labels
- away_team_image = ImageTk.PhotoImage(Image.open('bannerAway.bmp'))
- away_team_image_label = Label(root, image=away_team_image, border=0)
- away_team_image_label.grid(row=0, column=0)
- home_team_image = ImageTk.PhotoImage(Image.open('bannerHome.bmp'))
- home_team_image_label = Label(root, image=home_team_image, border=0)
- home_team_image_label.grid(row=0, column=3)
- # Game Time Label
- game_timer_label = Label(root, textvariable=current_game.timer, font=font_style_3, bg='black', fg='white')
- game_timer_label.grid(row=0, column=1, rowspan=2, columnspan=2)
- # Away Team Score
- away_team_score_label = Label(root, text=current_game.current_away_goals.get(),
- font=font_style_3, bg='black', fg='white')
- away_team_score_label.grid(row=1, column=0)
- # Home Team Score
- home_team_score_label = Label(root, text=current_game.current_home_goals.get(),
- font=font_style_3, bg='black', fg='white')
- home_team_score_label.grid(row=1, column=3)
- # Period Label
- period_image = ImageTk.PhotoImage(Image.open('bannerPeriod.bmp'))
- period_image_label = Label(root, image=period_image, border=0)
- period_image_label.grid(row=2, column=1, columnspan=2)
- # Period Indicator
- period_label_string = StringVar()
- period_label = Label(root, textvariable=period_label_string.get(), font=font_style_3, bg='black', fg='white')
- period_label.grid(row=3, column=1, columnspan=2)
- # Penalty Indicators
- penalty_image = ImageTk.PhotoImage(Image.open('bannerPenalty.bmp'))
- home_penalty_image_label = Label(root, image=penalty_image, border=0)
- home_penalty_image_label.grid(row=3, column=0)
- away_penalty_image_label = Label(root, image=penalty_image, border=0)
- away_penalty_image_label.grid(row=3, column=3)
- # Away Penalty
- away_penalty1_label = Label(root, text='0:00', font=font_style_3, bg='black', fg='white')
- away_penalty1_label.grid(row=4, column=0)
- away_penalty2_label = Label(root, text='0:00', font=font_style_3, bg='black', fg='white')
- away_penalty2_label.grid(row=5, column=0)
- # Home Penalty
- home_penalty1_label = Label(root, text='0:00', font=font_style_3, bg='black', fg='white')
- home_penalty1_label.grid(row=4, column=3)
- home_penalty2_label = Label(root, text='0:00', font=font_style_3, bg='black', fg='white')
- home_penalty2_label.grid(row=5, column=3)
- # Shots on Goal Indicator
- shots_image = ImageTk.PhotoImage(Image.open('bannerShots.bmp'))
- shots_image_label = Label(root, image=shots_image, border=0)
- shots_image_label.grid(row=4, column=1, columnspan=2)
- # Away Team Shots
- away_team_shots_string = StringVar()
- away_team_shots_string.set(current_game.away_team_shots)
- away_team_shots_label = Label(root, textvariable=away_team_shots_string.get(),
- font=font_style_3, bg='black', fg='white')
- away_team_shots_label.grid(row=5, column=1)
- # Home Team Shots
- home_team_shots_string = StringVar()
- home_team_shots_string.set(current_game.home_team_shots)
- home_team_shots_label = Label(root, textvariable=home_team_shots_string.get(),
- font=font_style_3, bg='black', fg='white')
- home_team_shots_label.grid(row=5, column=2)
- # =============================== #
- # Goal Assignment Window
- goal_assign_window = Toplevel()
- goal_assign_window.title("Goal Assignment")
- goal_assign_window.withdraw()
- goal_assign_player_team_label = Label(goal_assign_window, text='Team: ')
- goal_assign_player_team_label.grid(row=0, column=0)
- goal_assign_team_select_value = StringVar()
- goal_assign_team_select1 = Radiobutton(goal_assign_window, text="Home",
- variable=goal_assign_team_select_value, value='Home', width=10)
- goal_assign_team_select1.grid(row=0, column=1)
- goal_assign_team_select2 = Radiobutton(goal_assign_window, text="Away",
- variable=goal_assign_team_select_value, value='Away', width=10)
- goal_assign_team_select2.grid(row=0, column=2)
- goal_assign_player_label = Label(goal_assign_window, text='Scoring Player: ')
- goal_assign_player_label.grid(row=1, column=0)
- goal_assign_player_entry_value = StringVar()
- goal_assign_player_entry = Entry(goal_assign_window, textvariable=goal_assign_player_entry_value, width=2)
- goal_assign_player_entry.grid(row=1, column=1)
- assist1_assign_player_label = Label(goal_assign_window, text='Assist1 Player: ')
- assist1_assign_player_label.grid(row=2, column=0)
- assist1_assign_player_entry_value = StringVar()
- assist1_assign_player_entry = Entry(goal_assign_window, textvariable=assist1_assign_player_entry_value, width=2)
- assist1_assign_player_entry.grid(row=2, column=1)
- assist2_assign_player_label = Label(goal_assign_window, text='Assist2 Player: ')
- assist2_assign_player_label.grid(row=3, column=0)
- assist2_assign_player_entry_value = StringVar()
- assist2_assign_player_entry = Entry(goal_assign_window, textvariable=assist2_assign_player_entry_value, width=2)
- assist2_assign_player_entry.grid(row=3, column=1)
- game_time_goal_assign = Label(goal_assign_window, text='Game Time for Goal: ')
- game_time_goal_assign.grid(row=4, column=0)
- game_time_goal_assign_entry_value = StringVar()
- game_time_goal_assign_player_entry = Entry(goal_assign_window, textvariable=game_time_goal_assign_entry_value, width=5)
- game_time_goal_assign_player_entry.grid(row=4, column=1)
- goal_assign_period_label = Label(goal_assign_window, text='Period: ', font=font_style_1)
- goal_assign_period_label.grid(row=5, column=0, rowspan=3)
- goal_assign_period_value = 1
- goal_assign_period_one_radio = Radiobutton(goal_assign_window, text="1", variable=goal_assign_period_value, value="g1")
- goal_assign_period_one_radio.grid(row=5, column=1)
- goal_assign_period_one_radio = Radiobutton(goal_assign_window, text="2", variable=goal_assign_period_value, value="g2")
- goal_assign_period_one_radio.grid(row=6, column=1)
- goal_assign_period_one_radio = Radiobutton(goal_assign_window, text="3", variable=goal_assign_period_value, value="g3")
- goal_assign_period_one_radio.grid(row=7, column=1)
- goal_assign_player_entry_confirm = Button(goal_assign_window, text="OK", command=lambda: current_game.assign_goal())
- goal_assign_player_entry_confirm.grid(row=8, column=0, columnspan=3)
- # Penalty Assignment Window
- penalty_assign_window = Toplevel()
- penalty_assign_window.withdraw()
- penalty_assign_window.title("Penalty Assignment")
- penalty_assign_player_team_label = Label(penalty_assign_window, text='Team: ')
- penalty_assign_player_team_label.grid(row=0, column=0)
- penalty_assign_team_select_value = StringVar()
- penalty_assign_team_select1 = Radiobutton(penalty_assign_window, text="Home",
- variable=penalty_assign_team_select_value, value='Home', width=10)
- penalty_assign_team_select1.grid(row=0, column=1)
- penalty_assign_team_select2 = Radiobutton(penalty_assign_window, text="Away",
- variable=penalty_assign_team_select_value, value='Away', width=10)
- penalty_assign_team_select2.grid(row=0, column=2)
- penalty_assign_player_label = Label(penalty_assign_window, text='Penalized Player: ')
- penalty_assign_player_label.grid(row=1, column=0)
- penalty_assign_player_entry_value = StringVar()
- penalty_assign_player_entry = Entry(penalty_assign_window, textvariable=penalty_assign_player_entry_value, width=2)
- penalty_assign_player_entry.grid(row=1, column=1)
- game_time_penalty_assign = Label(penalty_assign_window, text='Game Time for Penalty: ')
- game_time_penalty_assign.grid(row=4, column=0)
- game_time_penalty_assign_entry_value = StringVar()
- game_time_penalty_assign_player_entry = Entry(penalty_assign_window,
- textvariable=game_time_penalty_assign_entry_value, width=5)
- game_time_penalty_assign_player_entry.grid(row=4, column=1)
- type_of_penalty_assign = Label(penalty_assign_window, text='Type of Penalty: ')
- type_of_penalty_assign.grid(row=5, column=0)
- type_of_penalty_assign_entry_value = StringVar()
- type_of_penalty_assign_player_entry = Entry(penalty_assign_window,
- textvariable=type_of_penalty_assign_entry_value, width=10)
- type_of_penalty_assign_player_entry.grid(row=5, column=1)
- penalty_assign_period_label = Label(penalty_assign_window, text='Period: ', font=font_style_1)
- penalty_assign_period_label.grid(row=6, column=0)
- penalty_assign_period_value = 1
- penalty_assign_period_one_radio = Radiobutton(penalty_assign_window,
- text="1", variable=penalty_assign_period_value, value="p1")
- penalty_assign_period_one_radio.grid(row=6, column=1)
- penalty_assign_period_one_radio = Radiobutton(penalty_assign_window,
- text="2", variable=penalty_assign_period_value, value="p2")
- penalty_assign_period_one_radio.grid(row=7, column=1)
- penalty_assign_period_one_radio = Radiobutton(penalty_assign_window,
- text="3", variable=penalty_assign_period_value, value="p3")
- penalty_assign_period_one_radio.grid(row=8, column=1)
- penalty_assign_player_entry_confirm = Button(penalty_assign_window,
- text="OK", command=lambda: current_game.assign_penalty())
- penalty_assign_player_entry_confirm.grid(row=9, column=0, columnspan=3)
- # =============================== #
- # Main Loop
- root.mainloop()
- # =============================== #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement