0

I am using the pafy module to download YouTube videos, but in one of the pafy functions, called download it prints to the screen the progress of the download, I would like to take that output and put it in my tkinter window.

Here is the pafy function:

video = pafy.new(url)
best_video = video.getbest(preftype="mp4")
write_prog("Started downloading "+video.title)
best_video.download()

The last function, best_video.download() is the one that prints to the screen.

Any ideas of how to do that?

CDspace
  • 2,639
  • 18
  • 30
  • 36
  • Create a class whose `write` method outputs to the Tkinter window. Reassign `sys.stdout` to that object. You may need to do the video download in a separate thread, so Tkinter gets enough processing cycles to refresh its window between writes. – Kevin Oct 08 '14 at 12:33
  • not sure why this got a downvote - it seems like a good qustion to me. I can think of two solutions : 1) redefine `sys.stdout` for the duration of the call so that it points to a `StringIO` (which looks like a file to any writing function/method), but can also be treated like a string, or 2) Run your download function as a separate process, and pipe the stdout of that process as appropriate. – Tony Suffolk 66 Oct 08 '14 at 12:52
  • @TonySuffolk66: I would guess the downvote is because the question, while interesting, shows no research effort. – Bryan Oakley Oct 08 '14 at 16:01
  • couldn't you create labels instead of 'printing' – W1ll1amvl Oct 08 '14 at 18:37

0 Answers0