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

Time:11-29

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.

    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 a random video from the TODO list

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()

^This will display the button

Nothing happens when I click the button. Any ideas?

CodePudding user response:

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)
  • Related