How to display a YouTube Video in Jupyter Notebook by Clicking a Button Using Tkinter

Question:

I’m trying to display a random YouTube Video from a list of 2 videos in my Jupyter notebook by displaying a button and clicking it.

This will display a random video from the TODO list

import random
from IPython.display import YouTubeVideo
TODO =  (YouTubeVideo('-C-ic2H24OU', width=800, height=300), YouTubeVideo('NpPDgrbmAYQ', width=800, height=300))
random_choice_from_my_list = random.choice(TODO)
random_choice_from_my_list

This will display the button

import tkinter as tk
def TODO_ACTIVITY():
    random_choice_from_my_list   
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame, 
                   text="TO DO", 
                   fg="black",
                   command=TODO_ACTIVITY)
button.pack(side=tk.LEFT)
root.mainloop()

Nothing happens when I click the button. Any ideas?

Asked By: Ricardo Barrios

||

Answers:

You need to use IPython.display.display() function to show the video:

...
from IPython.display import display

...
def TODO_ACTIVITY():
    random_choice_from_my_list = random.choice(TODO)
    display(random_choice_from_my_list)
Answered By: acw1668