Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

Pythons thorpy library AttributeError using thorpy.DropDownListLauncher in app

I'm working on some app and occured problem with one Thorpy element. Simple example here:

import pygame
import thorpy
pygame.init()
pygame.key.set_repeat(300, 30)
screen = pygame.display.set_mode((400, 400))
screen.fill((255, 255, 255))
rect = pygame.Rect((0, 0, 50, 50))
rect.center = screen.get_rect().center
clock = pygame.time.Clock()
values = ["option a", "option b", "option c"]
dropdownlist = thorpy.DropDownListLauncher.make(const_text="Choose something", var_text=values[0], titles=values)
box = thorpy.Box(elements=[dropdownlist])
menu = thorpy.Menu(box)

for element in menu.get_population():
    element.surface = screen
box.set_topleft((100, 100))
box.blit()
box.update()
playing_game = True
while playing_game:
    clock.tick(45)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            playing_game = False
            break
        menu.react(event) 
pygame.quit()

When trying to use dropdownlist AttributeError occurs:

Traceback (most recent call last):   
File "D:/app/test.py", line 45, in <module>
 menu.react(event) #the menu automatically integrate your elements   
File "D:appvenvlibsite-packageshorpymenusasicmenu.py", line 121, in react 
 element.react(event)   
File "D:appvenvlibsite-packageshorpyelementsghost.py", line 328, in react 
 reaction._try_activation(event)   
File "D:appvenvlibsite-packageshorpymiscgui
eaction.py", line 57, in _try_activation 
self.reac_func(**self.params)   
File "D:appvenvlibsite-packageshorpymiscguilauncherslauncher.py", line 253, in launch     
 self.prelaunch()   
File "D:appvenvlibsite-packageshorpymiscguilauncherslauncher.py", line 215, in prelaunch         
 self.activate_focus()   
File "D:appvenvlibsite-packageshorpymiscguilauncherslauncher.py", line 178, in 
 activate_focus self.save_active_records()   
File "D:appvenvlibsite-packageshorpymiscguilauncherslauncher.py", line 170, in save_active_records
 for e in menu.get_population(): 
AttributeError: 'NoneType' object has no attribute 'get_population'

Without this element in menu it works fine, my question is how to get rid of this error or make it another way?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...