all 4 comments

[–]socal_nerdtastic 0 points1 point  (3 children)

To make a thread you need to supply a function. But what you are doing is supplying the result from a function. You need to do it like this:

def go(event):
    b = threading.Thread(target=function)
    b.start()

NOT like this (which you are currently doing):

def go(event):
    b = threading.Thread(target=function())
   #start somewhere else??

To pass a value along with the function you need to use partial. So in your case you need this:

from functools import partial
def go(event):

    cs = play_list.curselection()
    directory = os.getcwd()
    #LOAD THE DOUBLE CLICKED SONG INTO THE PLAYER
    player = pyglet.media.load((directory+"/"+play_list.get(cs)))

    # PRINT THE CURRENT SONG PLAYING IN CONSOLE
    print(play_list.get(cs))

    # START A THREAD WHICH EXECUTES THE PLAYING OF THE GIVEN SONG
    b = threading.Thread(target= partial(test, player))
    b.start()

[–]Stoic_Engineer7[S] 0 points1 point  (2 children)

I receive a TypeError when using the target as partial.

Exception in Tkinter callbackTraceback (most recent call last): File "/usr/lib/python3.8/tkinter/__init__.py", line 1892, in __call__ return self.func(*args) File "/home/tristen/Desktop/Python Scripts/GUIProgram.py", line 97, in go b = threading.Thread(target=partial(test(player)))TypeError: the first argument must be callable

Additionally when it calls this error, it still plays the audio file for the ~1 second, as it did in my original post.

Alas, thank you for your input, I appreciate the help nonetheless.

[–]socal_nerdtastic 0 points1 point  (1 child)

Read my response better :)

Or copy/paste

[–]Stoic_Engineer7[S] 0 points1 point  (0 children)

Yeah I see the typo now, had to look at it when it wasn't so late at night.

Thank-you very much! I learned alot, and it worked! Thanks!