self.left_UsbCtrl = self.left_Lens_Usb.UsbCtrl AttributeError: module 'Lens' has no attribute 'UsbCtrl'
时间: 2024-05-10 17:13:18 浏览: 7
这个错误提示表明你正在尝试在一个名为"Lens"的模块中访问一个名为"UsbCtrl"的属性,但是这个模块中并没有这个属性。可能是因为你没有正确地导入该模块或者该模块中确实没有这个属性。请检查你的代码中是否正确导入了该模块,并且检查一下该模块中是否真的存在名为"UsbCtrl"的属性。如果有问题,请修改代码并重新运行。
相关问题
def input(self): keys = pygame.key.get_pressed() if self.can_move: if keys[pygame.K_RIGHT] and self.selection_index < self.attribute_nr - 1: self.selection_index += 1 self.can_move = False self.selection_time = pygame.time.get_ticks() elif keys[pygame.K_LEFT] and self.selection_index >= 1: self.selection_index -= 1 self.can_move = False self.selection_time = pygame.time.get_ticks() if keys[pygame.K_SPACE]: self.can_move = False self.selection_time = pygame.time.get_ticks() self.item_list[self.selection_index].trigger(self.player)
```
def input(self):
"""
处理用户输入
"""
keys = pygame.key.get_pressed()
if self.can_move:
# 如果允许移动
if keys[pygame.K_RIGHT] and self.selection_index < self.attribute_nr - 1:
# 如果按下右键并且当前选择索引小于属性数量减一
self.selection_index += 1
self.can_move = False
self.selection_time = pygame.time.get_ticks()
elif keys[pygame.K_LEFT] and self.selection_index >= 1:
# 如果按下左键并且当前选择索引大于等于1
self.selection_index -= 1
self.can_move = False
self.selection_time = pygame.time.get_ticks()
if keys[pygame.K_SPACE]:
# 如果按下空格键
self.can_move = False
self.selection_time = pygame.time.get_ticks()
# 触发当前选择的UI元素
self.item_list[self.selection_index].trigger(self.player)
```
这段代码是一个处理用户输入的函数。在该函数中,首先获取用户按键情况,并判断是否允许移动。如果允许移动,且用户按下了右键,并且当前选择的属性索引小于属性数量减一,则将选择的属性索引加一,并设置移动标志和选择时间。如果用户按下了左键,并且当前选择的属性索引大于等于1,则将选择的属性索引减一,并设置移动标志和选择时间。如果用户按下了空格键,则将移动标志设置为False,并触发当前选择的UI元素,即调用当前item_list列表中索引为选择的属性索引的元素的trigger()方法,并向其传递玩家对象作为参数。注释解释了该函数的功能和各个变量的含义。
对这段代码进行注释def __init__(self,player): self.display_surface = pygame.display.get_surface() self.player = player self.attribute_nr = len(player.stats) self.attribute_names = list(player.stats.keys()) self.max_values = list(player.max_stats.values()) self.font = pygame.font.Font(UI_FONT, UI_FONT_SIZE) self.height = self.display_surface.get_size()[1] * 0.8 self.width = self.display_surface.get_size()[0] // 6 self.create_items() # selection system self.selection_index = 0 self.selection_time = None self.can_move = True
```
def __init__(self, player):
"""
初始化函数,用于创建UI
:param player: 玩家对象
"""
# 获取显示表面
self.display_surface = pygame.display.get_surface()
# 设置玩家对象
self.player = player
# 玩家属性数量
self.attribute_nr = len(player.stats)
# 玩家属性名称列表
self.attribute_names = list(player.stats.keys())
# 玩家属性最大值列表
self.max_values = list(player.max_stats.values())
# 字体初始化
self.font = pygame.font.Font(UI_FONT, UI_FONT_SIZE)
# UI高度
self.height = self.display_surface.get_size()[1] * 0.8
# UI宽度
self.width = self.display_surface.get_size()[0] // 6
# 创建UI元素
self.create_items()
# 选择系统
self.selection_index = 0
self.selection_time = None
self.can_move = True
```
这段代码是一个类的初始化函数,用于创建UI。在该函数中,首先获取了显示表面和玩家对象,并设置了一些属性,如玩家属性数量、名称列表、最大值列表。同时,还初始化了字体、UI高度和UI宽度。之后,创建了UI元素,并定义了选择系统的变量。其中,选择系统的变量包括选择索引、选择时间和移动标志。注释解释了该函数的参数和功能,以及各个变量的含义。
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)