Closed MaxNacemit closed 4 years ago
What is the Python and Pygame version used ?
Python 3.6/Pygame 1.9
I cannot reproduce the bug. Are you reallly copy/pasting the code from the tutorial ? If so, can you post the entire error traceback with lines numbers ?
Same issue. I use Python 3.7.4/pygame 1.9.6/ThorPy 1.6.2
The bug happens when you include thorpy image object into another pygame code. It doesn't concern thorpy applications.
This is the tutorial on including thorpy in a pre-existing code. I replaced the make_button by make_image_button.
#Tutorial : how to use ThorPy with a pre-existing code - step 1
QUIT_BUTTON_IMAGE = "ressources/constantes/quitbuttonimage.png"
import pygame, 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()
pygame.draw.rect(screen, (255,0,0), rect)
pygame.display.flip()
#declaration of some ThorPy elements ...
slider = thorpy.SliderX(100, (12, 35), "My Slider")
button = thorpy.make_image_button(QUIT_BUTTON_IMAGE)
box = thorpy.Box(elements=[slider,button])
#we regroup all elements on a menu, even if we do not launch the menu
menu = thorpy.Menu(box)
#important : set the screen as surface for all elements
for element in menu.get_population():
element.surface = screen
#use the elements normally...
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
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
pygame.draw.rect(screen, (255,255,255), rect) #delete old
pygame.display.update(rect)
rect.move_ip((-5,0))
pygame.draw.rect(screen, (255,0,0), rect) #drat new
pygame.display.update(rect)
menu.react(event) #the menu automatically integrate your elements
pygame.quit()
Traceback :
C:\Users\godblessmassine\Anaconda3\python.exe D:/Desktop/bobbar/view/bullshit.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "D:/Desktop/bobbar/view/bullshit.py", line 20, in <module>
button = thorpy.make_image_button(QUIT_BUTTON_IMAGE)
File "C:\Users\godblessmassine\Anaconda3\lib\site-packages\thorpy\elements\_wrappers.py", line 148, in make_image_button
painter = ButtonImage(img_normal, img_pressed, img_hover, alpha, colorkey)
File "C:\Users\godblessmassine\Anaconda3\lib\site-packages\thorpy\painting\painters\imageframe.py", line 92, in __init__
mode, hovered)
File "C:\Users\godblessmassine\Anaconda3\lib\site-packages\thorpy\painting\painters\imageframe.py", line 19, in __init__
W, H = functions.get_screen_size()
File "C:\Users\godblessmassine\Anaconda3\lib\site-packages\thorpy\miscgui\functions.py", line 59, in get_screen_size
return get_current_application().size
AttributeError: 'NoneType' object has no attribute 'size'
Process finished with exit code
Same error happens when you use Image(path="path/to/an/image")
.
Also thank you for this lib, really helped me with my projects.
I updated the code so that it can be used outside of a thorpy application. Thanks for your useful comments !
I tried to integrate an image button into my pygame code, following the exact steps of the tutorial. It gave me the error of "NoneType object has no attribute 'size'". I traced it to the get_current_application function, which apparently returns nothing. When I replaced the image button with a button, everything started working.