-2

I am trying to see if a bool is true or false in a function but the program only returns SyntaxWarning: 'bool' object is not callable; perhaps you missed a comma? if Pianobool == True(): and this TypeError: 'bool' object is not callable When I look at it it looks like the bools are being assigned above the function. The bools are located pretty far down I just wanted to include all code because maybe it has to do with something else.

from faulthandler import dump_traceback
from tkinter import *
from playsound import playsound
import multiprocessing
import os
from multiprocessing import Process
import keyboard

root = Tk()

def Piano():
    playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Piano.mp3')

def Vocals():
        playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Vocals.mp3')

def Drums():
        playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Drum.mp3')

def Guitar():
        playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Guitar.mp3')

if __name__ == '__main__':
    p = multiprocessing.Process(target=Piano)
    D = multiprocessing.Process(target=Drums)
    V = multiprocessing.Process(target=Vocals)
    G= multiprocessing.Process(target=Guitar)

Pianobool = False
Guitarbool = False
Drumbool = False
Vocalbool = False

def PlayPiano():
        if Pianobool == True():
                p.terminate()
                Pianobool = False
        elif Pianobool == False():
                p.start()
                Pianobool = True

Pianobutton = Button(root,text='Piano',command=(PlayPiano))
Pianobutton.pack()
Guitarbutton = Button(root,text='Guitar')
Guitarbutton.pack()
Drumbutton = Button(root,text='Drums')
Drumbutton.pack()
Vocalbutton = Button(root,text='Vocals')
Vocalbutton.pack()

root.mainloop()
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 3
    Use `True` rather than `True()`. – BrokenBenchmark Mar 02 '22 at 18:12
  • 2
    Remove the parentheses from `True()` and `False()`. This is invalid. In fact, you don't even need the comparison, just do `if Piaonbool:`. – Code-Apprentice Mar 02 '22 at 18:12
  • Thanks for the anwser it solved the problem first but now I get this error UnboundLocalError: local variable 'Pianobool' referenced before assignment and to me it looks like the bools are assigned above the function – leoungsten Mar 02 '22 at 18:16
  • That's another problem: https://stackoverflow.com/questions/370357/unboundlocalerror-on-local-variable-when-reassigned-after-first-use – mkrieger1 Mar 02 '22 at 18:18

1 Answers1

1
Pianobool == True()
Pianobool == False()

By putting the parenthesis after True and False, you're signalling to the interpreter that you're trying to call them like a function. Just remove the parenthesis, and you should be good to go.

In fact, you usually don't have to check equality or inequality for Boolean values. You can just put the variable as the condition to the if or elif and Python will understand what you meant.

from faulthandler import dump_traceback
from tkinter import *
from playsound import playsound
import multiprocessing
import os
from multiprocessing import Process
import keyboard

root = Tk()


def Piano():
    playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Piano.mp3')


def Vocals():
    playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Vocals.mp3')


def Drums():
    playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Drum.mp3')


def Guitar():
    playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Guitar.mp3')


if __name__ == '__main__':
    p = multiprocessing.Process(target=Piano)
    D = multiprocessing.Process(target=Drums)
    V = multiprocessing.Process(target=Vocals)
    G = multiprocessing.Process(target=Guitar)

Pianobool = False
Guitarbool = False
Drumbool = False
Vocalbool = False


def PlayPiano():
    if Pianobool:
        p.terminate()
        Pianobool = False
    elif not Pianobool:
        p.start()
        Pianobool = True


Pianobutton = Button(root, text='Piano', command=(PlayPiano))
Pianobutton.pack()
Guitarbutton = Button(root, text='Guitar')
Guitarbutton.pack()
Drumbutton = Button(root, text='Drums')
Drumbutton.pack()
Vocalbutton = Button(root, text='Vocals')
Vocalbutton.pack()

root.mainloop()
eccentricOrange
  • 876
  • 5
  • 18
  • I did what you said but I still get the' UUnboundLocalError: local variable 'Pianobool' referenced before assignment' when the function try to run. – leoungsten Mar 02 '22 at 18:22
  • @leoungsten I suggest that you google the error. That one already has solutions here on Stack Overflow. This is a common situation where you fix one error and then get another one. Welcome to computer pogramming! – Code-Apprentice Mar 02 '22 at 18:43