gpt4 book ai didi

python - 在 pygame 窗口中创建一个工具栏

转载 作者:太空宇宙 更新时间:2023-11-04 01:15:24 25 4
gpt4 key购买 nike

如何在pygame中创建工具栏?我对此进行了初步搜索......并从http://en.flossmanuals.net/make-your-own-sugar-activities/making-activities-using-pygame/了解了它...但是 gi.repository 在 windows 中不起作用(我目前正在处理)。 python 中是否有任何其他库也可以在 windows 中工作,以便我可以添加..我实际上正在开发 GUI(大致可以解释为类似于文件夹中的图像在 pygame 窗口中继续向右滚动并且还有平移n 缩放功能实现。)。我只想在那个 pygame 窗口中有一个“工具栏”,并有两个按钮来暂停和开始滚动。

最佳答案

所以,考虑到评论(即你必须自己在 pygame 中制作),我没有更好的事情要做,所以我将概述你如何做。

将工具栏定义为一个类,您可以将它放在窗口的顶部并让它处理按钮:

class Toolbar:
def __init__(self, width, height): #And other customisation options
self.image = pygame.Surface(width, height)
self.image.fill(colour)
self.rect = self.image.get_rect()
self.rect.topleft = (0,0)
self.leftbutton = ButtonClass(args)
self.rightbutton = ButtonClass(args)

def update(self):
self.leftbutton.hover() #to animate an effect if the mouse hovers over
self.rightbutton.hover()

def draw(self, screen):
screen.blit(self.image, self.rect)
screen.blit(self.leftbutton.draw(), self.leftbutton.getRect())
screen.blit(self.rightbutton.draw(), self.rightbutton.getRect())

def click(pos):
if self.leftbutton.getRect().collidepoint(pos):
self.leftbutton.click()

if self.rightbutton.getRect().collidepoint(pos):
self.rightbutton.click()

这需要一个您可以自己制作的按钮类,但您也可以查看可用于我的网站的模块(这是我对方法调用的想法)http://tarqnet.sytes.net/projects/project-Pygame.html

从这里开始,实例化您的工具栏并在您的主循环中处理它:

toolbar = Toolbar(screen_width, 80)

while True:
toolbar.update()
toolbar.draw(screen)

#Other stuff
## Events:
## on left click call toolbar.click(pos)

关于python - 在 pygame 窗口中创建一个工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24970676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com