为什么PyGame鼠标点击检测工作不正确?

2024-09-30 06:30:44 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:

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之间,它应该要求更改字体。这很好。但是,对于滞后切换按钮,当我单击按钮中间或左边时,它会要求更改字体。为什么会这样


Tags: andposdefaultgetifpygamelagfile

热门问题