Reputation: 25
So I'm quite new to Tkinter, and Python as a whole. I am working on a project that gets lyrics from the internet, and either simply displays them to you, or uses a Markov Chain to generate a random song. I've got the code working, I'm just trying to implement a GUI now. I've gotten to the point where you can enter a song and the artist, and the program will give you the lyrics. For now though, the lyrics still come out in the console. I'm now trying to get the lyrics into the GUI, but when I try to put them in the text is cut off. I used a tutorial for the tkinter part of things, so I'm not sure which part of the code is relevant. The text in question being cut off is in the GetLyrics class.(lyric_label) Currently just using "example" as a placeholder. Thank you so much in advance and please tell me if I've done anything incorrectly in this post.
This is a picture of the problem:
import get_lyrics
import textwrap
import tkinter as tk
from tkinter import ttk
from cc_markov import MarkovChain
lyric_data = MarkovChain()
LARGE_FONT = ("Verdana", 12)
small_font = ("Verdana", 10)
class lyrGenApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.iconbitmap(self, "logo.ico")
tk.Tk.wm_title(self, "LyrGen")
tk.Tk.wm_geometry(self, '1024x576')
self.resizable(False, False)
container = tk.Frame(self)
container.pack(side="top", fill="both")
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, GenLyrics, GetLyrics):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Lyrgen", font=LARGE_FONT)
label.pack(pady=10, padx=10)
gen_button = ttk.Button(self, text="Generate Lyrics",
command=lambda:
controller.show_frame(GenLyrics))
gen_button.pack()
get_button = ttk.Button(self, text="Get Lyrics",
command=lambda:
controller.show_frame(GetLyrics))
get_button.pack()
class GenLyrics(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Generate Lyrics", font = LARGE_FONT)
label.pack(pady = 10, padx = 10)
button1 = ttk.Button(self, text="Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class GetLyrics(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Get Lyrics", font = LARGE_FONT)
label.place(relx = 0.5, rely = 0.3, anchor = 's')
prompt_song = tk.Label(self, text = "Enter Song:", font = small_font)
prompt_song.place(relx = 0.38, rely = 0.6, anchor = 's')
prompt_artist = tk.Label(self, text = "Enter Artist:", font =
small_font)
prompt_artist.place(relx = 0.38, rely = 0.8, anchor = 's')
song_entry = tk.Entry(self)
song_entry.place(relx = 0.5, rely = 0.6, anchor = 's')
artist_entry = tk.Entry(self)
artist_entry.place(relx = 0.5, rely = 0.8, anchor = 's')
home_button = ttk.Button(self, text="Home",
command=lambda: controller.show_frame(StartPage))
home_button.place(relx = 0.1, rely = 0.7, anchor = 's')
lyric_label = tk.Label(self, text = "example", font = small_font,
justify = "left")
lyric_label.place(relx = .1, rely = .85)
lyrics = []
def get_button(list):
lyrics = list
print(" ".join(lyrics))
search_button = ttk.Button(self, text="Search", command= lambda:
get_button(get_lyrics.get_song(song_entry.get(),
artist_entry.get())))
search_button.place(relx = 0.6, rely = 0.7, anchor = 's')
app = lyrGenApp()
app.mainloop()
Upvotes: 1
Views: 2124
Reputation: 5414
Reduce value of rely
to .8
or .75
or something like this in this line:
lyric_label.place(relx = .1, rely = .85)
Change to :
lyric_label.place(relx = .1, rely = .8)
or
lyric_label.place(relx = .1, rely = .75)
Upvotes: 1