'I get "TypeError: 'bool' object is not callable" when I have very clearly stated the bool above [closed]
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()
Solution 1:[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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
