SFML community forums
Bindings - other languages => Python => Topic started by: 8Observer8 on May 16, 2017, 01:58:17 pm
-
Hello,
It is my first pySFML window. I get the code from here: https://www.python-sfml.org/gettingstarted.html
But I get this error:
AttributeError: module 'sfml.sf' has no attribute 'CloseEvent'
This is my code. I commented some things because I need only empty window:
from sfml import sf
# create the main window
window = sf.RenderWindow(sf.VideoMode(640, 480), "pySFML Window")
try:
pass
# load a sprite to display
#texture = sf.Texture.from_file("cute_image.png")
#sprite = sf.Sprite(texture)
## create some graphical text to display
#font = sf.Font.from_file("arial.ttf")
#text = sf.Text("Hello SFML", font, 50)
## load music to play
#music = sf.Music.from_file("nice_music.ogg")
except IOError: exit(1)
# play the music
#music.play()
# start the game loop
while window.is_open:
# process events
for event in window.events:
# close window: exit
if type(event) is sf.CloseEvent:
window.close()
window.clear() # clear screen
#window.draw(sprite) # draw the sprite
#window.draw(text) # draw the string
window.display() # update the window
-
I remember that there has been multiple versions and IIRC that the documentation wasn't updated for the latest changes.
So I suggest to take a look at the Python binding source code to see what the API actually is.
-
Thank you very much :)
# start the game loop
while window.is_open:
# process events
for event in window.events:
# close window: exit
if event == sf.Event.CLOSED:
window.close()