Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: My First pySFML Window. Error: AttributeError: module 'sfml.sf' has no attribute  (Read 1852 times)

0 Members and 1 Guest are viewing this topic.

8Observer8

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
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:
Quote
AttributeError: module 'sfml.sf' has no attribute 'CloseEvent'

This is my code. I commented some things because I need only empty window:
Code: [Select]
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
« Last Edit: May 16, 2017, 02:50:39 pm by 8Observer8 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9573
    • View Profile
    • development blog
    • Email
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

8Observer8

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Thank you very much  :)

Code: [Select]
# 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()