0

I'm learning tkinter and I decided to make a small youtube-dl GUI as a project. This is my code so far.

from Tkinter import *
import youtube_dl
root = Tk()

myLabel = Label(root, text="YOUTUBE-DL MUSIC").grid(column=1, row=1)
linkput = Entry(root, width=50)
linkput.grid(column=1, row=2)


def downloadsong():
    linkval = linkput.get()
    params = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
        'source_address': '0.0.0.0',}
    youtube = youtube_dl.YoutubeDL(params)
    youtube.download([linkval])
    outputtext = Label(root, text="Downloaded")
    outputtext.grid(column=1, row=3)


downloadbutton = Button(root, text="Download", padx=50, command=downloadsong).grid(column=2, row=2)
root.mainloop()

So, I'm using the python module of youtube-dl to download the link of whatever is in the entry box. The GUI works so far, but I want to print the terminal output as a label. I can see in the terminal, ex. Video: "Learn Tkinter!" Download: 80% Is it possible to have this terminal output put into a tkinter label? I could try using subprocess.check_output() but I'd prefer using the python module instead of the CLI. Also, since the terminal output changes (the percent progress), I'm not sure if that would work in a label.

ZackT
  • 61
  • 4
  • First of I don't see any `print` functions in Your code, secondly it is most likely possible at the very least with threads but probably easier – Matiiss May 10 '21 at 18:37
  • I don't know of a way to put it into a `Label` but you can send a script's output to an independent tkinter window via pipes. See the `errorwindow3k.py` module in [this answer](https://stackoverflow.com/a/49016673/355230) of mine to another question for an example that redirects `stderr` (and `stdout`) from the _current_ script to one. – martineau May 10 '21 at 18:40
  • @Matiiss You don't have to print, the library prints it. – Delrius Euphoria May 10 '21 at 18:45
  • btw does the function that prints it returns anything or does it have an option to not print? Nevermind, I took a quick glance at the so called "docs" (which are non-existant) but what `PyPl` said is that it is a command line thingy so it seems You will have to use @martineau suggested answer – Matiiss May 10 '21 at 18:59
  • You can use the `logger` option in `params`. See example in [`youtube_dl website`](https://github.com/ytdl-org/youtube-dl#embedding-youtube-dl). – acw1668 May 12 '21 at 03:49

0 Answers0