Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Output console to a text widget for Tkinter GUI

Ive been working on a simple youtube downloader as a project to build up some practice with the Tkinter module. The issue i'm running into is that i'm not quite sure how to output the content of the console into a text box widget as well as handling the download function running on a separate thread simultaneously.

Here is an example of what I how I want it to output:
[Image: convert.png]


Here is my code:
(I know its clunky with a ton of unnecessary imports)

PHP Code

<?php 
from __future__ import unicode_literals
import tkinter
from tkinter import 
*
import os
import sys
from shutil import copytree
, ignore_patterns
import youtube_dl
import os
.path
from os import path
import ctypes
import time
import threading



def redirector
(inputStr):
 
   text_out.insert(INSERT, inputStr)

def convert(url_list):

 
   
    
#youtube options for each downloaded video 
 
   ydl_opts = {
 
       'format': 'bestaudio/best',
 
       'postprocessors': [{
 
           'key': 'FFmpegExtractAudio',
 
           'preferredcodec': 'mp3',
 
           'preferredquality': '192',
 
       }],
 
   }

 
   #Converts a list of youtube URLs
 
   with youtube_dl.YoutubeDL(ydl_opts) as ydl:
 
       ydl.download(url_list)

def get_text():

 
   content = body.get(1.0, "end-1c")
 
   
    content_list 
= content.split('\n')
 
   content_list_ref = []
 
   for url in content_list:
 
       content_list_ref.append(url.strip(' '))

 
   if len(content_list_ref) < 2: 
 
       print("No Video URL Entered")
 
   else:
 
       t1 = threading.Thread(target=convert, args=(content_list_ref,))
 
       t1.start()
 
       t1.join()
 
   


#main window
master = tkinter.Tk()
master.geometry("700x480")
master.title("Simple Youtube Downloader")
master.resizable(False, False)

#URL text box
body = tkinter.Text(master, height=16, width=50, borderwidth=3)
body.place(x=10, y=10)

#Large YouTube icon
canvas = Canvas(master, width = 300, height = 300)      
canvas
.place(x=420, y=-50)      
img 
= PhotoImage(file='YoutubeDownloader\icon.png')     
canvas
.create_image(20,20, anchor=NW, image=img) 

#Download Button
button = tkinter.Button(master, text="Download", width=20, height=2, command=lambda:[get_text()])
button.place(x=490, y=350)

#Dev credit
label = Label(master, text="")
label.place(x=525, y=450)

#Bottom console window
text_out = Text(master, height=10, width=50)
text_out.place(x=11, y= 300)



master.mainloop() 


Any help would be heavily appreciated.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by GruntStylFeb 26, 2025 08:25 PM 5 267 Feb 26, 2025 08:25 PM
Last Post: GruntStyl
[Python] by MiguelSanchezApr 12, 2022 02:13 PM 1 158 Apr 12, 2022 02:13 PM
Last Post: lightduty
[Python] by RevNucleusJul 24, 2021 10:40 PM 2 154 Jul 24, 2021 10:40 PM
Last Post: RevNucleus