鼠标点击IS不被识别

发布于 2025-01-20 03:32:52 字数 800 浏览 0 评论 0原文

我试图在单击时使黑色单元格变成白色单元格,反之亦然。我似乎无法解决的问题是,无论我使用什么功能,当我单击鼠标时,我的程序都无法识别。我已经尝试了谷歌上的几乎所有搜索结果和堆栈溢出上的答案,但没有任何反应。这就是我目前正在使用的。

 def update(self, event_list):
        for event in event_list:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if self.rect.collidepoint(event.pos):
                    self.alive = not self.alive
        if self.alive:
            self.image = self.alive_image
        else:
            self.dead_image
   #main loop
   while gen:
       event_list = pygame.event.get()
       for event in event_list:
           if event.type == pygame.QUIT:
               run = false

       all_cells.update(event_list)

       clock.tick(60)
   pygame.quit()

我还尝试了所有常用的函数,例如 pygame.mouse.get_press() 和 self.rect.collidepoint()。我应该尝试什么?

I am trying to make a black cell become a white cell when clicked, and vise versa. The problem that I can't seem to solve is that no matter what function I use, my program doesn't recognize when I click my mouse. I've tried just about every search result on both google and answer on stack overflow, but nothing happens. This is what I am currently using.

 def update(self, event_list):
        for event in event_list:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if self.rect.collidepoint(event.pos):
                    self.alive = not self.alive
        if self.alive:
            self.image = self.alive_image
        else:
            self.dead_image
   #main loop
   while gen:
       event_list = pygame.event.get()
       for event in event_list:
           if event.type == pygame.QUIT:
               run = false

       all_cells.update(event_list)

       clock.tick(60)
   pygame.quit()

I also tried all the usual functions like pygame.mouse.get_press() and self.rect.collidepoint(). What should I try?

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

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

发布评论

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

评论(1

但可醉心 2025-01-27 03:32:52

您需要用

        if self.alive:
            self.image = self.alive_image
        else:
            self.dead_image

AS self.dead_image代码

        if self.alive:
            self.image = self.alive_image
        else:
            self.image = self.dead_image

替换您的代码什么都没做。

You'll need to replace your

        if self.alive:
            self.image = self.alive_image
        else:
            self.dead_image

With

        if self.alive:
            self.image = self.alive_image
        else:
            self.image = self.dead_image

As at self.dead_image the code isn't doing anything.

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