Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
830 views
in Technique[技术] by (71.8m points)

python - Show thumbnail of youtube video in canvas using pytube and tkinter

i want to show a yt video's thumbnail using tkinter and pytube but it won't work my code is as follow:

from tkinter import *
import urllib.request, io
from PIL import ImageTk, Image
from pytube import YouTube


sc= Tk()

def show_pic():
    yt = YouTube('https://www.youtube.com/watch?v=sVPYIRF9RCQ')
    raw_data = urllib.request.urlopen(yt.thumbnail_url).read()
    im = Image.open(io.BytesIO(raw_data)).resize((200, 200))
    image = ImageTk.PhotoImage(im)
    c.create_image(0,0, anchor='nw', image=image)

c = Canvas(sc, width=200, height=200)
c.pack()

btn = Button(sc, text='Show', command=show_pic)
btn.pack()



sc.mainloop()
question from:https://stackoverflow.com/questions/65920195/show-thumbnail-of-youtube-video-in-canvas-using-pytube-and-tkinter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...