当前位置:网站首页>[pyGame learning notes] 6 Cursor mouse cursor
[pyGame learning notes] 6 Cursor mouse cursor
2022-07-19 13:04:00 【Leleprogrammer】
Pygame Provide control of system hardware cursor .Pygame Support black and white cursor ( Bitmap cursor ), And system variant cursor and color cursor .
This cursor module contains functions for loading and decoding various cursor formats . These allow the cursor to be easily stored in an external file or directly as encoded Python character string .
This module includes several standard cursors , The parameters of these cursors are stored in a tuple .
This time, , Let's learn Pygame Cursor operation in pygame.cursor
stay Pygame In the official documents of , We can see that there are three ways to import the cursor :
pygame.cursors.compile # Create binary cursor data from simple strings
pygame.cursors.load_xbm # from XBM File loading cursor data
pygame.cursors.Cursor # Represents the cursor pygame object
We still give the initial framework first :
import pygame
from pygame.locals import *
import sys
class Game:
def __init__(self):
pygame.init()
self.W,self.H=800,800
self.screen=pygame.display.set_mode((self.W,self.H))
pygame.display.set_caption("【Pygame Learning notes 】")
def listen(self):
for event in pygame.event.get():
if event.type==QUIT:
sys.exit()
def draw(self):
self.screen.fill((255,255,255))
def run(self):
while True:
self.listen()
self.draw()
pygame.display.update()
if __name__ == '__main__':
game=Game()
game.run()pygame.cursors There are several standard cursors below :
pygame.cursors.arrow
pygame.cursors.diamond
pygame.cursors.broken_x
pygame.cursors.tri_left
pygame.cursors.tri_right
Examples are as follows :
pygame.mouse.set_cursor(pygame.cursors.arrow)

pygame.mouse.set_cursor(pygame.cursors.diamond)
![]()
pygame.mouse.set_cursor(pygame.cursors.broken_x)
![]()
pygame.mouse.set_cursor(pygame.cursors.tri_left)

pygame.mouse.set_cursor(pygame.cursors.tri_right)

The module also contains some cursors as formatted strings . They need to be passed to pygame.cursors.compile() function , Then we can use them .
pygame.cursors.textmarker_strings
pygame.cursors.textmarker_strings
pygame.cursors.sizer_x_strings
pygame.cursors.sizer_y_strings
pygame.cursors.sizer_xy_strings
One when typing “I” cursor
cursor=pygame.cursors.compile(pygame.cursors.textmarker_strings)
pygame.mouse.set_cursor((8,16),(0,0),*cursor)Along x Coordinate the cursor when dragging the window
cursor=pygame.cursors.compile(pygame.cursors.sizer_x_strings)
pygame.mouse.set_cursor((24,16),(0,0),*cursor)Along y Coordinate the cursor when dragging the window
cursor=pygame.cursors.compile(pygame.cursors.sizer_y_strings)
pygame.mouse.set_cursor((16,24),(0,0),*cursor)Along xy Coordinate the cursor when dragging the window ( Cursor at the corner of the window )
cursor=pygame.cursors.compile(pygame.cursors.sizer_xy_strings)
pygame.mouse.set_cursor((24,16),(0,0),*cursor)Be careful , These four cursors are all composed of a tuple , There are several strings in the tuple , If we treat strings as arrays , It's just a two-dimensional array , therefore set_cursor The first tuple passed in later is this “ Two dimensional array ” Size , It can be used len Method and index , View these tuples directly , You can also be like it , Create your own cursor
The explanation of this tuple in the official document is as follows :
thickarrow_strings = ( #sized 24x24 "XX ", "XXX ", "XXXX ", "XX.XX ", "XX..XX ", "XX...XX ", "XX....XX ", "XX.....XX ", "XX......XX ", "XX.......XX ", "XX........XX ", "XX........XXX ", "XX......XXXXX ", "XX.XXX..XX ", "XXXX XX..XX ", "XX XX..XX ", " XX..XX ", " XX..XX ", " XX..XX ", " XXXX ", " XX ", " ", " ", " ")
The reference code of this learning note is as follows :
import pygame
from pygame.locals import *
import sys
class Game:
def __init__(self):
pygame.init()
self.W,self.H=800,800
self.screen=pygame.display.set_mode((self.W,self.H))
pygame.display.set_caption("【Pygame Learning notes 】")
def listen(self):
for event in pygame.event.get():
if event.type==QUIT:
sys.exit()
def draw(self):
self.screen.fill((255,255,255))
# pygame.mouse.set_cursor(pygame.cursors.arrow)
# cursor=pygame.cursors.compile(pygame.cursors.textmarker_strings)
# pygame.mouse.set_cursor((8,16),(0,0),*cursor)
# cursor=pygame.cursors.compile(pygame.cursors.sizer_x_strings)
# pygame.mouse.set_cursor((24,16),(0,0),*cursor)
# cursor=pygame.cursors.compile(pygame.cursors.sizer_y_strings)
# pygame.mouse.set_cursor((16,24),(0,0),*cursor)
cursor=pygame.cursors.compile(pygame.cursors.sizer_xy_strings)
pygame.mouse.set_cursor((24,16),(0,0),*cursor)
def run(self):
while True:
self.listen()
self.draw()
pygame.display.update()
if __name__ == '__main__':
game=Game()
game.run()It's not easy to make , If you like, just like the collection + Pay attention ~
Thank you for your support ~
边栏推荐
猜你喜欢
![[error record /selectpicker] the display position of dropdown menu is offset](/img/92/78787b33b941f09d753f0f747f8c72.png)
[error record /selectpicker] the display position of dropdown menu is offset

CMOS开关学习(一)

R语言--Cox模型校准曲线原理(一)数据来源

备赛笔记:matplotlib学习笔记a
[email protected] Cobalt iron bimetallic organic skeleton cox/mil-100 (FE) | [email protected]

Basic database operations in MySQL

Stable super odds, 9 years old mixin | 2022 Jincang innovative product launch was successfully held

市场“不确定性”中的投资逻辑 2020-03-18
[email protected] )|Rhodamine 6G modified MOF material | catalase @zif composite | MOF"/>Lanthanide metal organic skeleton( [email protected] )|Rhodamine 6G modified MOF material | catalase @zif composite | MOF

Return to risk ratio: the most important indicator of investment opportunities 2020-03-14
随机推荐
Binary tree 2-symmetry recursion problem
GO 单元测试
The active and standby cache of redis cluster is full, causing frequent active and standby switchover
Interview difficulties: difficulties in implementing distributed session, this is enough!
Acwing4405. Statistical submatrix
2022 global developer salary exposure: China ranks 19th, with an average annual salary of $23790
Ultrasonic sensor (chx01) learning notes Ⅲ - I2C reading and writing operation
C语言进阶——字符函数和字符串函数
Ultrasonic sensor (ch101 & ch201) - I
【Pygame 学习笔记】6.Cursor 鼠标光标
Google developer community sharing - flutter animation sharing has been released
2022年最新吉林建筑安全员模拟题库及答案
XML建模(简单易学)
力扣413-等差数列划分——动态规划
Porphyrin encapsulated organometallic frame materials [email protected] |
運維小白成長記—架構第6周
力扣198-213 打家劫舍Ⅰ、Ⅱ——动态规划
LeetCode 0117. 填充每个节点的下一个右侧节点指针 II
[error record /selectpicker] the display position of dropdown menu is offset
The difference and use between get request and post request