So I am on a python class at school each monday, we have just gone through the whole The python tutorial. I have started to experiment with diffrent modules and some with pygames. My ultimate goal is to create a ripoff on Chip challenge^^
Yesterday I started to build an backpack solution for use in pygame, or anything really where you need to store something. I though that the WX moudle would do the grapichal trick, sins it is very easy to make one in just plain text.
Anyway, I came pretty far, though I got a bug. I am not sure if it is pygame or wx causing the bug, but it feels like it could be pygame, don really can explain why but from my little experience, it feel that way
Here is the code:
- Code: Select all
import wx, pygame
from pygame.locals import *
pygame.init()
if __name__ == '__main__':
app=wx.PySimpleApp()
size = width, height = 800, 600
screen = pygame.display.set_mode(size)
backpack = ['Medallion', 'Knife'] # This should be a reguluar list.
while 1:
keyinput = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:sys.exit()
if keyinput[K_UP]:
a = wx.SingleChoiceDialog(None, "5 item slots:", "Backpack", backpack)
if a.ShowModal() == wx.ID_OK:
print "You select %s" % a.GetStringSelection()
if keyinput[K_DOWN]:
backpack.insert( 0,'Arrow')
#These booth lines seems to do the same thing, only that insert uses a position.
if keyinput[K_LEFT]:
backpack.append('Arrow')
The bug is that whenever I press the down key( as is just a random thing for adding stuff), the backpack will be filled with the 'Arrow'. I just want 'Arrow' to be inserted onceeach key press
So do any have any idea of how I can solove this?