为什么Pygame鼠标单击检测无法正常工作?

时间:2019-03-02 21:33:25

标签: python python-3.x pygame mouse

这是我的代码:

if mgc == 0 and event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pos() >= (250, 15) and pygame.mouse.get_pos() <= (363, 51):
    ofnt_thing = input("What font would you like your score to be in? ")
    if ofnt_thing == "":
        file = open("fontdefault.txt", "r+")
        default = file.read()
        print("Set to default: " + default)
        ofnt_thing = default
        file.close()
    elif ofnt_thing == "set_default()":
        newfile = open("fontdefault.txt", "w+")
        newdef = input("New default font: ")
        newfile.write(newdef)
        ofnt_thing = newdef
        newfile.close()
    ofnt = pygame.font.SysFont(str(ofnt_thing), 50)
    stxt = ofnt.render(str(score), False, (255, 20, 255))
if mgc == 0 and event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pos() >= (250, 65) and pygame.mouse.get_pos() <= (437, 100):
    if lag == True: lag = False
    else: lag = True

因此,当我运行程序的这一部分时,如果鼠标的x值在250到363之间,而y值在15到51之间,则应该询问字体更改。这很好。但是,对于滞后切换按钮,当我单击按钮的中间或左侧时,它会要求更改字体。为什么会这样?

0 个答案:

没有答案