python - The code does not work when I update a variable -


i'm trying display 2 images of cards in simple gui(can accessed online @ http://www.codeskulptor.org/#user41_8poew9pxi8_1.py)

import simplegui  #images displayed ace_hearts = simplegui.load_image("http://i.imgur.com/nbr6dzi.png") two_spades = simplegui.load_image("http://i.imgur.com/owayj1t.png")  # global constants width = 800 height = 100   # mouseclick handler def click(pos):     return pos   # draw handler def draw(canvas):     img_width = 67     img_height = 100     img_center = [img_width // 2, img_height // 2]     canvas.draw_image(two_spades, (img_center),          (img_width, img_height), (img_center), (img_width, img_height))     img_center[0] += img_width     canvas.draw_image(ace_hearts, (img_center),          (img_width, img_height), (img_center), (img_width, img_height))  # create frame , register draw handler     frame = simplegui.create_frame("test image", width, height) frame.set_canvas_background("gray") frame.set_mouseclick_handler(click) frame.set_draw_handler(draw)  # start frame frame.start() 

the problem is, when update value of img_center[0], code won't display second image "ace-hearts".

then remove line

img_center[0] += img_width 

the second image correctly displayed "on top" of "two-spades".

does know why updating variable won't produce correct results (ace-hearts should displayed right of two-hearts)?

second , fourth parameter given draw_image center_source , center_dest. when draw second image need keep center_source same , modify center_dest:

def draw(canvas):     img_width = 67     img_height = 100     source_center = [img_width // 2, img_height // 2]     dest_center = [img_width // 2, img_height // 2]     canvas.draw_image(two_spades, (source_center),          (img_width, img_height), (dest_center), (img_width, img_height))     dest_center[0] += img_width     canvas.draw_image(ace_hearts, (source_center),          (img_width, img_height), (dest_center), (img_width, img_height)) 

working example: http://www.codeskulptor.org/#user41_5cm7zlarnq_0.py


Comments