Getting into the new Python / Pygm. I am trying to make a death counter for my Twitter stream.
I'm finally going to use it GUI, but for now I have to run it back in the field and add a +1 to number in 1 key file. 2 Resets that number to 0.
An error is happening on line 19.
The file "C: /Pththon27/Deathcounter.py", line 1 9, & lt; Module & gt; If event.key == pygame.K_1: AttributeError: Event member is not defined
In addition to this, I am certain that I have always completed the process as I do. I
# death counter import package, sys import pygame.locals # variable dial-deck = float (0) pygame.init () black = (0,0,0) WIDTH = 320 HEIGHT = 260 windsurfaces = pajamas display. Set_mode ((WIDTH, HEIGHT), 0, 32) windowSurface.fill (BLACK) while true: event = pygame.event.get (for event) event: if event.key == pygame.K_1: open ("deathcounter As_file: if_file as out_file.write (deathcount): deathcount = in_file.read () deathcount = deathcount + 1 with open ("deathcounter.txt", "wt") as if event.key = = Pygame .K_2: with open ("deathcounter.txt", "wt") as the deathcount = 0 out_file: out_file.write (deathcount) if if event.type == QUIT: pygame.quit () sys.exit ()
Thanks for the advice / help.
In all events Not key feature, this is the It is a ray that you get this error.
Also for the first time you open your file to read, this one was not present, so it will take an exception.
# Import the Death Counter Import the Pygam import system pygame.locals # variable deathcount = float (0) pygame.init () BLACK = (0, 0, 0) WIDTH = 320 HEIGHT = 260 windowSurface = pygame.display.set_mode (( WIDTH, height), 0, 32) window highfile Fill (black) while true: event = pygame.event.get () for event occurring in events: if the hatter (event, 'key'): if event.key == pygame.K_1: try: forms of in_file With open ("deathcounter.txt", "r"): deathcount = int (in_file.read ()) except deathcount = deathcount + 1 (IOError, ValueError), err: print error deathcount = 0 Open ("deathcounter" Out_file.write (str (deathcount)) as if the event.key == pygame.K_2: number of deaths = 0 open ("deathcounter.txt", "W"). Please exit out_file: out_file.write (str (deathcount)) if event.type == pygame.event.QUIT: pygame.quit () sys.exit ()
For Informations, the key to capture the key in the background is not good to use PyGame because it will require that pygame windows have active focus. So if you are using windows, then I recommend you take a look at this example which uses PyHook: on other Linux, see Python X11 Library
Comments
Post a Comment