0

I'm trying to search videos on youtube using youtubesearchpython library and trying to create GUI for the same.

The problem is when ever I search, my GUI stop functioning so I decided to use thread in threading lib. Now my GUI is working fine but ever I run my program threading run automatically and I can't recall search() again using "search" button.

What I want is search() function run when ever i click on "search" button.

here is my code

from tkinter import *
from tkinter import ttk
from youtubesearchpython import VideosSearch
from threading import Thread
root = Tk()
root.title("wrong threading")
class searching:
    def __init__(self,root):
        self.root = root
        self.label_list = []
        self.label_frame = Frame(self.root)
        self.label_frame.pack()

        self.entry_var = StringVar()
        self.entry_box = Entry(self.label_frame,textvariable = self.entry_var)

        self.thread_obj = Thread(target = self.search)
        
        self.entry_box.pack(anchor = "w")
        self.search_btn = ttk.Button(self.label_frame,text = "search",command = self.thread_obj.start())
        self.search_btn.pack(anchor = "w")
        
        self.root.mainloop()
    def search(self):
        self.label_list = []
        to_search = self.entry_var.get()
        video_search = VideosSearch(to_search,limit = 5)
        result = video_search.result()
        for i in range(5):
            self.label_list.append( Label(self.label_frame,text = result['result'][i]['title']).pack())
            

    
obj = searching(root)

0 Answers0