我試圖通過顯示一個按鈕并單擊它來從我的 Jupyter 筆記本中的 2 個視頻串列中顯示一個隨機的 YouTube 視頻。
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
^這將顯示 TODO 串列中的隨機視頻
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()
^這將顯示按鈕
當我單擊按鈕時沒有任何反應。有任何想法嗎?
uj5u.com熱心網友回復:
您需要使用IPython.display.display()功能來顯示視頻:
...
from IPython.display import display
...
def TODO_ACTIVITY():
random_choice_from_my_list = random.choice(TODO)
display(random_choice_from_my_list)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/370474.html
上一篇:我怎樣才能把它變成一個按鈕?
