我收到“TypeError:‘bool’”对象不可调用”当我非常清楚地说明上面的布尔值时

发布于 2025-01-11 04:14:46 字数 1469 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摘星┃星的人 2025-01-18 04:14:46
Pianobool == True()
Pianobool == False()

通过在 TrueFalse 之后放置括号,您可以向解释器发出信号,表明您正在尝试像函数一样调用它们。只需删除括号,您就可以开始了。

事实上,您通常不必检查布尔值的相等或不相等。您只需将变量作为 ifelif 的条件,Python 就会理解您的意思。

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()
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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文