For learning more about Python and tkinter I am writing a YouTube downloader. I have a separate window where you can add a link and press a button which should display the thumbnail and title inside my main window. Right now I just got the title working.
Here is the function:
def display_yt_video(self, title):
thumbnail = tk.PhotoImage(file='thumbnail.gif')
photo_label = tk.Label(root, image=thumbnail)
photo_label.pack()
yt_label = tk.Label(gui.bottomFrame, text=title)
yt_label.pack()
It seems like he can't find the right "root" object, no error is showing. I tried to use the window "root" and also in multiple frames. I managed to open this picture in another program in exactly this way.
Here is my striped down Code:
from pytube import YouTube
import tkinter as tk
import urllib.request
root = tk.Tk()
class Gui:
def add_url_window(self):
ck_button = tk.Button(url_topframe, text='Add to Queue')
ck_button.bind('<Button-1>', dl.check_url)
ck_button.grid(row=2, column=2, padx=10)
class Downloader():
def check_url(self, event):
#try:
url = self.retrieve_input()
thumbnail_url = YouTube(url).thumbnail_url
urllib.request.urlretrieve(thumbnail_url, "thumbnail.gif")
yt_title = YouTube(url).title
print('done')
dl.display_yt_video(yt_title)
def display_yt_video(self, title):
thumbnail = tk.PhotoImage(file='thumbnail.gif')
photo_label = tk.Label(root, image=thumbnail)
photo_label.pack()
yt_label = tk.Label(gui.bottomFrame, text=title)
yt_label.pack()
dl = Downloader(root)
gui = Gui()
root = tk.Tk()
menu = tk.Menu()
root.config(menu=menu)
gui.build_window()
root.mainloop(