Pygame Function Book
Project description
Pygame Function Book
pygame be used easier
1.下载 download
pip install pgbook
2.简单的程序 easiest program
1.esay
from pgbook.screen.window import Window
mywindow = Window()
#窗口对象
mywindow.show()
#展示
'''
这段代码生成了一个空白窗口
'''
2.window
from pgbook.screen.window import Window
mywindow = Window()
#窗口对象
mywindow.set_name('Hello World')
#set_name:用于修改名称
mywindow.set_ico('logo.ico')
#set_ico:用于设置图标
mywindow.set_rect(0.4,0.4)
#set_rect:(w,h):
# w,h<=1 大小为屏幕大小的w,h倍
# w,h>1 大小为w,h
mywindow.show()
#展示
'''
这段代码展示了Window类的使用
'''
3.事件系统
from pgbook.eventlist.thinglist import Thing,ThingList
t=Thing()
#单个事件对象
# 设置事件 方式1
def k(get1,get2):
print(str(get1)+' and '+str(get2))
t.connect(k)
# 设置事件 方式2
@t.connect()
def k(get1,get2):
print(str(get1)+' and '+str(get2))
t.set_name('PrintA')
#设置对象名称,用于寻找
t.did(256,None)
#输出:256 and None
#did:执行,传入参数
t.did_n(1024,False)
#输出:256 and False
#did_n:如果名称符合则执行,传入参数
t.lock(True)# 上锁did did_n不执行(也不报错)
t.lock(False)# 开锁 默认
t.lock()# 更改锁的方向
tl=ThingList()
# 事件列表,可叠多层
tl.set_name('PrintList')#检索名称
tl.lock(True)#锁功能同上,不执行本列表,但子对象不上锁
#添加事件 方式1
tl.connect(t)#Thing或ThingList均可,但不可传入自身,以防锁死
#添加事件 方式2
@tl.connect(name='PrintA')
def k(get1,get2):#注意保持参数统一
print(str(get1)+' and '+str(get2))
#自动创建一个Thing对象,name为'PrintA'
tl.did('pan',64)#所有对象执行,同时受本身和子对象的锁影响
tl.did_n('apple',64)#名称正确对象执行
tl.lock_n('PrintA')
#给所有name='PrintA'的对象上锁
#不受tl.lock(True)的影响
tl.find_n('PrintA')
#返回第一个name='PrintA'的对象
#不受tl.lock(True)的影响
tl.find_n('PrintA').did()
'''
这段代码展示了事件系统的使用
'''
4.Window中的事件
from pgbook.screen.window import Window
import pygame
mywindow = Window()
#帧事件 mywindow.check
#实例
mywindow.MaxFps = 10
k=1
@mywindow.check.connect(name='TenTimesCheck')
def TTC(screen):#mywindow.check 有固定参数 screen
global k
k+=1
if k==11:
print('Check!')
k=1
'''
大约每秒输出一次
'''
#事务 mywindow.event
#实例
@mywindow.event.connect(name='MouseDown')
def MD(event):#mywindow.event 有固定参数 event
if event.type == pygame.MOUSEBUTTONDOWN:
# 获取鼠标点击的位置
mouse_pos = pygame.mouse.get_pos()
# 在控制台输出鼠标点击的位置
print("鼠标点击位置:", mouse_pos)
'''
鼠标点击则输出
'''
mywindow.show()
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 Distribution
pgbook-0.1.17.tar.gz
(6.0 MB
view details)
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 pgbook-0.1.17.tar.gz.
File metadata
- Download URL: pgbook-0.1.17.tar.gz
- Upload date:
- Size: 6.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.10 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8232f36fb51e8e7c610412c8f00de096c99a7a3276af86e3d6428c6ddc488ad9
|
|
| MD5 |
3a194e5f8f2e0595d16be00e4a4694d7
|
|
| BLAKE2b-256 |
918dbbd9a3621b9bebe446a9f308c465d10db93a8126fdb7e78b3bd4448f89cb
|
File details
Details for the file pgbook-0.1.17-py3-none-any.whl.
File metadata
- Download URL: pgbook-0.1.17-py3-none-any.whl
- Upload date:
- Size: 6.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.10 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72f2f9b57871c85956a82766531b55fc0705f0c3dc052b47a2b9a585bd41ea3f
|
|
| MD5 |
e6c29ad07b34b7498dc3aab5cdbae1d1
|
|
| BLAKE2b-256 |
58faa8e91045e5984e6a129fe17bc5986e58d2e4c720f794f6595f01a18d5980
|