如何单击并转到Pygame中的另一个页面?

时间:2018-12-08 18:39:18

标签: python pygame

因此,我正在为学校作业编写此代码,应该使用pygame并显示一些文本。我将这些文本放在不同的页面中,如果单击该屏幕,它将显示下一个屏幕。

这是我到目前为止所拥有的:

var newJson = '[{"firstname":{"value":"lan","condition":"EQUAL","operator":1,"type":"stringfilter","id":38}},{"firstname":{"value":"Lars","condition":"EQUAL","operator":1,"type":"stringfilter"}}]';

var addNewfilter = function (data) {
data = JSON.parse(data)
   let arr = []
   for (var j = 0; j < data.length; j++) {
     let obj = data[j];
     for (var key in obj) {
       if (obj.hasOwnProperty(key)) {
         var filtergroup = new $.jqx.filter();
         let filter_or_operator = obj[key].operator;
         let filtervalue = obj[key].value;
         let filtercondition = obj[key].condition;
         let filter = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
         filtergroup.addfilter(filter_or_operator, filter);
         $("#jqxgrid").jqxGrid('addfilter', key, filtergroup);
       }
     }
   }
  $("#jqxgrid").jqxGrid('applyfilters');
}

尽管它不起作用,但有人可以帮忙吗?谢谢!

2 个答案:

答案 0 :(得分:2)

您一开始就定义了button = 0,但是从不在主循环中更改其值。在drawIntro函数中,选中if button > 0if button == 1 因此,显然,您永远不会执行任何if条语句。

您需要通过调用pygame.mouse.get_pressed()抓住鼠标按钮,并弄清楚如何正确切换到下一页。

顺便说一句,您也有3次if button == 1,这不是我想的,因为if语句在编写时将立即执行,因此第3页将立即显示。您需要一些计数器来跟踪下次按下鼠标按钮时需要显示的页面。

答案 1 :(得分:1)

当用户按下鼠标按钮时,您需要增加button计数器。

不应在事件循环中为每个drawIntro调用一次pygame.MOUSEMOTION函数,而应在主while循环中调用一次。另外,将MOUSEMOTION更改为MOUSEBUTTONDOWN,以使每次点击增加一次button

drawIntro函数中的条件不正确。

import pygame


pygame.init()
SIZE = (1000, 700)
screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()
button = 0
fontIntro = pygame.font.SysFont("Times New Roman",30)


def drawIntro(screen):
    #start
    if button == 0:  # == 0
        screen.fill((0, 0, 0))
        text = fontIntro.render("Sigle click to start", 1, (255,255,255))
        screen.blit(text, (300, 300, 500, 500))
    elif button == 1:  #page1
        screen.fill((0, 0, 0))
        text = fontIntro.render("page 1", True, (255, 255, 255))
        screen.blit(text, (300,220,500,200))
    elif button == 2:  #page2
        screen.fill((0, 0, 0))
        text = fontIntro.render("page 2", True, (255, 255, 255))
        screen.blit(text, (300,220,500,200))
    elif button == 3:  #page3
        screen.fill((0, 0, 0))
        text = fontIntro.render("page3", True, (255, 255, 255))
        screen.blit(text, (200,190,500,200))


running = True
while running:
    for evnt in pygame.event.get():
        if evnt.type == pygame.QUIT:
            running = False
        if evnt.type == pygame.MOUSEBUTTONDOWN:  # Once per click.
            button += 1

    drawIntro(screen)
    pygame.display.flip()

pygame.quit()