GUI Application for Live Cricket scoreboard Using Python

04 Dec, 2021
In this article, we will see how sports.py module is imported and implemented to produce scoreboard of a specified sport like baseball, basketball, cricket and many more along with other details about the sport. Code examples in the text below revolve around cricket, you can perform the same operation for any other sport.
Sport.py Scrapes data from:
scorespro.com
pro-football-reference.com
baseball-reference.com
basketball-reference.com
hockey-reference.com
Not all sports are supported by this module, all of which are supported are listed below along with their respective python code to reference them:
First, we need to install this module and for that just simply run the following code into your terminal:
pip install sports.py
import module
Get a single match using get_match()
Syntax-
get_match(sport, team1, team2)
get_match() returns a single Match object which contains the following properties:
Example 1:
Python3
# import moduleimport sports # setting sportsports.get_match(sports.CRICKET, 'KINGS XI PUNJAB' , 'ROYAL CHALLENGERS BANGALORE')
Output:
Example 2:
Program that prints all live cricket matches.
Python3
# import moduleimport sports # extracting informationmatches = sports.get_sport(sports.CRICKET) #printing all matchesfor item in matches:    print(item)
Output:
 
Example 3:
An application that produces cricket live scores using tkinter in a GUI format.
Python3
# import modulesfrom tkinter import *import sportsfrom tkinter import messagebox def cricket_info():         try:        match = sports.get_match(sports.CRICKET, e1.get() , e2.get())        date.set(match.match_date)        time.set(match.match_time)        league.set(match.league)        team1.set(match.home_team)        team2.set(match.away_team)        team1_score.set(match.away_score)        team2_score.set(match.home_score)        link.set(match.match_link)    except:        messagebox.showerror("showerror", "No match found")    # object of tkinter# and background set for light greymaster = Tk()master.configure(bg='light grey') # Variable Classes in tkinterdate = StringVar();time = StringVar();league = StringVar();team1 = StringVar();team2 = StringVar();team1_score = StringVar();team2_score = StringVar();link = StringVar(); # Creating label for each information# name using widget LabelLabel(master, text="Team 1 :" , bg = "light grey").grid(row=0, sticky=W)Label(master, text="Team 2 :" , bg = "light grey").grid(row=1, sticky=W)Label(master, text="Date :" , bg = "light grey").grid(row=2, sticky=W)Label(master, text="Time :", bg = "light grey").grid(row=3, sticky=W)Label(master, text="League :", bg = "light grey").grid(row=4, sticky=W)Label(master, text="Team 1 :", bg = "light grey").grid(row=5, sticky=W)Label(master, text="Team 2 :", bg = "light grey").grid(row=6, sticky=W)Label(master, text="Team 1 score :", bg = "light grey").grid(row=7, sticky=W)Label(master, text="Team 2 score :", bg = "light grey").grid(row=8, sticky=W)Label(master, text="Link :", bg = "light grey").grid(row=9, sticky=W)  # Creating label for class variable# name using widget EntryLabel(master, text="", textvariable= date ,bg = "light grey").grid(row=2,column=1, sticky=W)Label(master, text="", textvariable= time ,bg = "light grey").grid(row=3,column=1, sticky=W)Label(master, text="", textvariable= league ,bg = "light grey").grid(row=4,column=1, sticky=W)Label(master, text="", textvariable= team1 ,bg = "light grey").grid(row=5,column=1, sticky=W)Label(master, text="", textvariable= team2 ,bg = "light grey").grid(row=6,column=1, sticky=W)Label(master, text="", textvariable= team1_score ,bg = "light grey").grid(row=7,column=1, sticky=W)Label(master, text="", textvariable= team2_score ,bg = "light grey").grid(row=8,column=1, sticky=W)Label(master, text="", textvariable= link ,bg = "light grey").grid(row=9,column=1, sticky=W)  e1 = Entry(master)e1.grid(row=0, column=1) e2 = Entry(master)e2.grid(row=1, column=1) # creating a button using the widget # Button that will call the submit functionb = Button(master, text="Show", command=cricket_info )b.grid(row=0, column=2,columnspan=2, rowspan=2,padx=5, pady=5) mainloop()
Output:
nnr223442
Python Tkinter-exercises
Python-tkinter
python-utility
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.