Integrated Pygame application development support.
Project description
GTC Pygame Runtime Support
集成 Pygame 应用开发支持
Finding an English version? click here
нашли русскую версию? кликните сюда
此软件包可用于 Pygame 应用开发,包括但不限于游戏、窗体应用,应于版本大于 3.4.0 的 Python 环境中运行。
软件包安装
向绝大多数软件包一样,本软件包也可使用 pip 下载并安装
pip install GTC_Pygame_Runtime_Support
如果 pip 不慎爆炸,您可以从 Github 处直接复制源码
使用示例
按钮
PRS 提供三种按钮类型,全部位于button.py文件内,此处以其中的FeedbackButton为例进行展示
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((200, 200))
button = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 15, screen, bg_color=[0, 145, 220],
border_color=[209, 240, 255], text_color=[255, 255, 255],
change_color=((0, 145, 220), (0, 225, 0))) # 生成按钮
running = 1
clock = pygame.time.Clock()
while running: # 主循环
screen.fill((255, 255, 255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
button.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3)) # 按钮贴图处
if button.on_click:
print("clicked")
pygame.display.flip()
clock.tick(60)
运行如上代码,你将能够创建一个显示文字为 114 的按钮,并且点击这个按钮后,控制台会输出"clicked",并且根据用户的动作,按钮将会有不同的反馈。
页面
PRS 提供的页面类型位于page.py内,此处以PlainPage为例进行展示
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)
if __name__ == '__main__':
clock = pygame.time.Clock()
bp.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
bp.set_as_background()
mw = [False, False]
while True:
mw = [False, False]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
mw[1] = True
elif event.button == 5:
mw[0] = True
bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
pygame.display.flip()
clock.tick(60)
运行上述代码,你将能够创建一个可由鼠标滚轮滚动和鼠标左键拖动的页面,你可以自行更换其背景,只要你在主循环前调用函数bp.set_as_background()
PRS 中的嵌套操作
在 PRS 中,一切展示型组件都可通过托管 (trusteeship) 的方式进行嵌套。
在页面中嵌套按钮
PRS 中所有组件托管按钮的方式均相同,就像下面展示的:
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)
if __name__ == '__main__':
clock = pygame.time.Clock()
bp.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
bp.set_as_background()
bt = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 10, bp.surface)
bp.add_button_trusteeship(bt)
mw = [False, False]
while True:
mw = [False, False]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
mw[1] = True
elif event.button == 5:
mw[0] = True
bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
if bt.on_click:
print('clicked')
pygame.display.flip()
clock.tick(60)
PRS 通常通过item.add_button_trusteeship(button)的形式添加嵌套按钮,同时按钮声明时的目标 surface 应指向被嵌套对象的 surface,通常是item.surface。
在页面中嵌套页面
原理基本同上。
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)
if __name__ == '__main__':
clock = pygame.time.Clock()
bp.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
bp.set_as_background()
inner_p = gPRS.page.PlainPage([100, 100], [100, 300], [50, 200], bp.surface, wheel_support=True)
inner_p.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(inner_p.surface, [0, 0, 255], [0, 9 * i], [300, 9 * i])
inner_p.set_as_background()
bp.add_page_trusteeship(inner_p)
mw = [False, False]
while True:
mw = [False, False]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
mw[1] = True
elif event.button == 5:
mw[0] = True
bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
pygame.display.flip()
clock.tick(60)
通过以上介绍,您应该能对 PRS 的使用特点有大概的了解。
想要获取完整文档?点击前往语雀文档
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file GTC_Pygame_Runtime_Support-0.0.14-py2.py3-none-any.whl.
File metadata
- Download URL: GTC_Pygame_Runtime_Support-0.0.14-py2.py3-none-any.whl
- Upload date:
- Size: 42.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34b47610b252d05f687973bbd4a4a8839b23a11b46dfb5c0938188948a62fe0f
|
|
| MD5 |
f83d61b37e3dd0ed2f355e16551c6128
|
|
| BLAKE2b-256 |
7966f13f8f53abdf20cdfce889e55a571026acc37f4c6398cfa01c77ea0ada34
|