-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyrics-gui.py
executable file
·50 lines (36 loc) · 1.18 KB
/
lyrics-gui.py
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
#!/usr/bin/python3
from lyrics_extractor import SongLyrics
import sys
import tkinter as tk
# API and Search engine
extract_lyrics = SongLyrics("API-KEY", "ENGINE-ID")
query = ""
# Check for cli arguments, [0] is always filename
if len(sys.argv) > 1:
args = sys.argv
for a in args[1:]:
query = query + " " + a
# Otherwise, prompt for input
else:
query = input("Lyrics search: ")
song = extract_lyrics.get_lyrics(query)
# print(song)
# Open the main window & start the Tcl interpreter
root = tk.Tk()
# Make a Frame to hold the Text widget and its Scrollbar
frame = tk.Frame(root)
frame.pack()
# Add the Scrollbar first so that it doesn't
# disappear when the window width is small
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Add the Text widget
viewer = tk.Text(root, wrap="word", yscrollcommand=scrollbar.set)
viewer.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
# Connect the Scrollbar to the Text widget
scrollbar.config(command=viewer.yview)
# Get the file name from the command line
# fname = sys.argv[1]
# Read the text file and add its contents to the Text widget
viewer.insert(tk.END, song['title'] + "\n\n" + song['lyrics'])
root.mainloop()