Python 2.7 tkinter card matching game -



Python 2.7 tkinter card matching game -

ok, have project school , create matching card game using python 2.7. here code.

import sys import tkinter import random tkinter import * #==== main window ====# root=tk() root.title('matching game') root.geometry('750x770+400+20') #===== load images =====# back= photoimage(file='images/back.gif') card1=photoimage(file='images/card_front_01.gif') card2=photoimage(file='images/card_front_02.gif') card3=photoimage(file='images/card_front_03.gif') card4=photoimage(file='images/card_front_04.gif') card5=photoimage(file='images/card_front_05.gif') card6=photoimage(file='images/card_front_06.gif') card7=photoimage(file='images/card_front_07.gif') card8=photoimage(file='images/card_front_08.gif') card9=photoimage(file='images/card_front_09.gif') cards=[card1,card2,card3,card4,card5,card6,card7,card8,card9] useable=[] useable.append(cards[random.randrange(0,9)]) useable.append(cards[random.randrange(0,9)]) useable.append(cards[random.randrange(0,9)]) useable.append(cards[random.randrange(0,9)]) useable.append(cards[random.randrange(0,9)]) useable.append(cards[random.randrange(0,9)]) f1=useable[random.randrange(0,6)] f2=useable[random.randrange(0,6)] f3=useable[random.randrange(0,6)] f4=useable[random.randrange(0,6)] f5=useable[random.randrange(0,6)] f6=useable[random.randrange(0,6)] f7=useable[random.randrange(0,6)] f8=useable[random.randrange(0,6)] f9=useable[random.randrange(0,6)] f10=useable[random.randrange(0,6)] f11=useable[random.randrange(0,6)] f12=useable[random.randrange(0,6)] #===========front=======# front1=label(image=f1) front1.grid(row=1,column=1) front2=label(image=f2) front2.grid(row=1,column=2) front3=label(image=f3) front3.grid(row=1,column=3) front4=label(image=f4) front4.grid(row=1,column=4) front5=label(image=f5) front5.grid(row=2,column=1) front6=label(image=f6) front6.grid(row=2,column=2) front7=label(image=f7) front7.grid(row=2,column=3) front8=label(image=f8) front8.grid(row=2,column=4) front9=label(image=f9) front9.grid(row=3,column=1) front10=label(image=f10) front10.grid(row=3,column=2) front11=label(image=f11) front11.grid(row=3,column=3) front12=label(image=f12) front12.grid(row=3,column=4) #========functions======# def flip(y): global step,card1,card2 if step==1: button.config(image=all[the_cards][y][0]) card1=x step=2 elif step==2: button.config(image=all[the_cards][y][0]) card2=x step=3 if card[card1][0]==card[card2][0]: card[card1][1]=1 card[card2][1]=1 step=0 #=======back======# button=button(image=back,command=lambda:flip(1)) button.grid(row=1,column=1) button=button(image=back,command=lambda:flip(2)) button.grid(row=1,column=2) button=button(image=back,command=lambda:flip(3)) button.grid(row=1,column=3) button=button(image=back,command=lambda:flip(4)) button.grid(row=1,column=4) button=button(image=back,command=lambda:flip(5)) button.grid(row=2,column=1) button=button(image=back,command=lambda:flip(6)) button.grid(row=2,column=2) button=button(image=back,command=lambda:flip(7)) button.grid(row=2,column=3) button=button(image=back,command=lambda:flip(8)) button.grid(row=2,column=4) button=button(image=back,command=lambda:flip(9)) button.grid(row=3,column=1) button=button(image=back,command=lambda:flip(10)) button.grid(row=3,column=2) button=button(image=back,command=lambda:flip(11)) button.grid(row=3,column=3) button=button(image=back,command=lambda:flip(12)) button.grid(row=3,column=4) #=========main program=======# the_cards=[[0,0]] all=[1,2,3,4,5,6,7,8,9] random.shuffle(all) all=all[0:6] all=all*2 random.shuffle(all) in range(0,12): the_cards.append([the_cards[i],0]) card1=100 card2=101 step=1 root.mainloop()

my error "line 106, in flip button.config(image=all[the_cards][y][0]) typeerror: list indices must integers, not list"

can please tell me why isn't working , how prepare it? thanks!!!

well, error message gives away problem right away.

trust in error message: telling problem is. "list indices must integers, not list"

when all[the_cards], inquire "what the_cards?"

python tkinter

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -