So I have another problem(new project new code), with a rather lengthy code. The problem is I am getting tkinter errors left and right and I can't find why. The error I get is:

File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "N:\dkaul\CLASS-VSFX160-01\sklock20\Python\blackjack\Black.py", line 212, in <module>
c0=c.create_image(394,215,image=picme3)
File "C:\Python25\lib\lib-tk\Tkinter.py", line 2154, in create_image
return self._create('image', args, kw)
File "C:\Python25\lib\lib-tk\Tkinter.py", line 2145, in _create
*(args + self._options(cnf, kw))))
TclError: image "pyimage108" doesn't exist

Or something along those lines with another picture, or even another pyimage#.

from Tkinter import *
from random import *
from math import *
import os

root=Tk()
root.title('Blackjack v.01')
c=Canvas(win, width=1006, height=700)
c.pack()

#Table image 
#182, 131 user space start
#182, 40 dealer space start
#cards need 17pxl to see full info
bg=(PhotoImage(file="table.gif"))
c0=c.create_image(394,215,image=bg)

# card database
deck=PhotoImage(file="deck.gif")

cdata={
  0:{'pic':'Ac.gif','val':11,'desc':'Ace of Clubs'},
  1:{'pic':'Ad.gif','val':11,'desc':'Ace of Diamonds'},
  2:{'pic':'Ah.gif','val':11,'desc':'Ace of Hearts'},
  3:{'pic':'As.gif','val':11,'desc':'Ace of Spades'},
  4:{'pic':'2c.gif','val':2,'desc':'2 of Clubs'},
  5:{'pic':'2d.gif','val':2,'desc':'2 of Diamonds'},
  6:{'pic':'2h.gif','val':2,'desc':'2 of Hearts'},
  7:{'pic':'2s.gif','val':2,'desc':'2 of Spades'},
  8:{'pic':'3c.gif','val':3,'desc':'3 of Clubs'},
  9:{'pic':'3d.gif','val':3,'desc':'3 of Diamonds'},
  10:{'pic':'3h.gif','val':3,'desc':'3 of Hearts'},
  11:{'pic':'3s.gif','val':3,'desc':'3 of Spades'},
  12:{'pic':'4c.gif','val':4,'desc':'4 of Clubs'},
  13:{'pic':'4d.gif','val':4,'desc':'4 of Diamonds'},
  14:{'pic':'4h.gif','val':4,'desc':'4 of Hearts'},
  15:{'pic':'4s.gif','val':4,'desc':'4 of Spades'},
  16:{'pic':'5c.gif','val':5,'desc':'5 of Clubs'},
  17:{'pic':'5d.gif','val':5,'desc':'5 of Diamonds'},
  18:{'pic':'5h.gif','val':5,'desc':'5 of Hearts'},
  19:{'pic':'5s.gif','val':5,'desc':'5 of Spades'},
  20:{'pic':'6c.gif','val':6,'desc':'6 of Clubs'},
  21:{'pic':'6d.gif','val':6,'desc':'6 of Diamonds'},
  22:{'pic':'6h.gif','val':6,'desc':'6 of Hearts'},
  23:{'pic':'6s.gif','val':6,'desc':'6 of Spades'},
  24:{'pic':'7c.gif','val':7,'desc':'7 of Clubs'},
  25:{'pic':'7d.gif','val':7,'desc':'7 of Diamonds'},
  26:{'pic':'7h.gif','val':7,'desc':'7 of Hearts'},
  27:{'pic':'7s.gif','val':7,'desc':'7 of Spades'},
  28:{'pic':'8c.gif','val':8,'desc':'8 of Clubs'},
  29:{'pic':'8d.gif','val':8,'desc':'8 of Diamonds'},
  30:{'pic':'8h.gif','val':8,'desc':'8 of Hearts'},
  31:{'pic':'8s.gif','val':8,'desc':'8 of Spades'},
  32:{'pic':'9c.gif','val':9,'desc':'9 of Clubs'},
  33:{'pic':'9d.gif','val':9,'desc':'9 of Diamonds'},
  34:{'pic':'9h.gif','val':9,'desc':'9 of Hearts'},
  35:{'pic':'9s.gif','val':9,'desc':'9 of Spades'},
  36:{'pic':'10c.gif','val':10,'desc':'10 of Clubs'},
  37:{'pic':'10d.gif','val':10,'desc':'10 of Diamonds'},
  38:{'pic':'10h.gif','val':10,'desc':'10 of Hearts'},
  39:{'pic':'10s.gif','val':10,'desc':'10 of Spades'},
  40:{'pic':'Jc.gif','val':10,'desc':'Jack of Clubs'},
  41:{'pic':'Jd.gif','val':10,'desc':'Jack of Diamonds'},
  42:{'pic':'Jh.gif','val':10,'desc':'Jack of Hearts'},
  43:{'pic':'Js.gif','val':10,'desc':'Jack of Spades'},
  44:{'pic':'Qc.gif','val':10,'desc':'Queen of Clubs'},
  45:{'pic':'Qd.gif','val':10,'desc':'Queen of Diamonds'},
  46:{'pic':'Qh.gif','val':10,'desc':'Queen of Hearts'},
  47:{'pic':'Qs.gif','val':10,'desc':'Queen of Spades'},
  48:{'pic':'Kc.gif','val':10,'desc':'King of Clubs'},
  49:{'pic':'Kd.gif','val':10,'desc':'King of Diamonds'},
  50:{'pic':'Kh.gif','val':10,'desc':'King of Hearts'},
  51:{'pic':'Ks.gif','val':10,'desc':'King of Spades'},
  }

im=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",]

for i in range(52):
  im[i]=PhotoImage(file=cdata[i]['pic'])


  
# load money
def loadmoney():
  file = os.path.join("data", "usr_money.txt")
  if os.path.exists(file):
    hs = open(os.path.join("data", "high_score.sav"), "r").read()
    return int(hs)
  else:
    hs = open(os.path.join("data", "usr_money.txt"), "w").write(str(0))
    return 0

#save money
def savemoney():
  open(os.path.join("data", "usr_money.txt"), "w").write(str(score))


  

# gets card
def getcard():
  global drawn,b
  cardsused=[]
  b=random.randint(0,51)
  if not b in cardsused:
    cardsused.append[b]
    drawn=cdata[b]['value']
  else:
    getcard()
  if len(cardsused) == 52:
    cardsused.clear

# Bank
def bankme():
  global usrm,game
  if not game == 1:
    usrm=usrm+500
    drawbox['text']="You drew from the bank"

# New hand
def newhand():
  global bet,usrm,game,drawn,usrhand,comphand
  usrhand=[]
  comphand=[]
  betamount()
  drawbox['text']=""
  drawbox2['text']=""
  if not game == 1:
    getcard()
    comphand.append[drawn]
    d1=c.create_image(182,40,image=deck)
    getcard()
    usrhand.append[drawn]
    u1=c.create_image(182,131,image=im[b])
    getcard()
    comphand.append[drawn]
    d2=c.create_image(199,40,image=im[b])
    getcard()
    usrhand.append[drawn]
    u2=c.create_image(199,131,image=im[b])
    game = 1

# values computation
def computatate(hand):
  aces = hand.count(11)
  t = sum(hand)
  if t > 21 and aces > 0:
    while aces > 0 and t > 21:
      t -= 10
      aces -= 1

# hit proc
def hitme():
  global game,drawn,usrhand,comphand,ut,ct
  if game == 1:
    getcard()
    usrhand.append[drawn]
    drawbox['text']="You drew the "+cdata[drawn]['desc']
    ct=computate(comphand)
    if ct < 18:
      getcard()
      comphand.append[drawn]
    if ut >= 21:
      stayme()

# Game over proc
def gameover():
  global game,usrm,ut,ct,bet
  game = 0
  if ut > 21:
    drawbox['text']="You broke!"
    drawbox2['text']="You lose "+bet
    usrm=usrm-bet
  elif ut == 21:
    drawbox['text']="You got a blackjack!"
    drawbox2['text']="You win "+bet*1.5
    usrm=usrm+bet*1.5
  elif ut > ct:
    drawbox['text']="You beat the computer!"
    drawbox2['text']="You win "+bet*1.5
    usrm=usrm+bet*1.5
  elif ct > ut and ct < 22:
    drawbox['text']="The computer won..."
    drawbox2['text']="You lose "+bet
    usrm=usrm-bet
  elif ct > 21:
    drawbox['text']="The computer broke!"
    drawbox2['text']="You win "+bet*1.5
    usrm=usrm+bet*1.5
  elif ut == ct:
    drawbox['text']="You tied!"
    drawbox2['text']="You lose NOTHING!"

    
# stay proc
def stayme():
  global drawn,comphand,stay,ct
  stay = 1
  while ct < 18:
    getcard()
    comphand.append[drawn]
    ct=computate(comphand)
  gameover()
    

# Bet amount
def betamount():
  global bet
  bet=scl.get()

#Window
root=Tk()
c=Canvas(win, width=1006, height=700)
c.pack()

#Table image 
#182, 131 user space start
#182, 40 dealer space start
#cards need 17pxl to see full info
picme3=(PhotoImage(file="table.gif"))
c0=c.create_image(394,215,image=picme3)

# Create buttons and slider
hit=Button(text='Hit Me',font=("Times",12,"bold","italic"),fg="white",bg="DodgerBlue4",command=hitme)
stay=Button(text='Stay',font=("Times",12,"bold","italic"),fg="white",bg="DodgerBlue4",command=stayme)
quit=Button(text='Quit',bg="plum3",command=root.destroy)
betscl=Scale(root, orient=HORIZONTAL,length=200,label="Bet",fg="black",font=("Times",12,"bold","italic"),troughcolor = "DarkSeaGreen2", from_=5, to=50, tickinterval=5, resolution=.01)
save=Button(text='Save Money',font=("Times",12,"bold","italic"),fg="white",bg="DodgerBlue4",command=savemoney)
load=Button(text='Load Money',font=("Times",12,"bold","italic"),fg="white",bg="DodgerBlue4",command=loadmoney)
bank=Button(text='Get a Loan',font=("Times",12,"bold","italic"),fg="white",bg="DodgerBlue4",command=bankme)
hand=Button(text='New Game',font=("Times",12,"bold","italic"),fg="white",bg="DodgerBlue4",command=newhand)
drawbox=Label(text="", bg="white", font=('Times',10)).pack(side=LEFT,expand=YES)
drawbox2=Label(text="",bg="white",font=('Times',10)).pack(side=RIGHT,expand=YES)

quit.pack(expand=YES,fill=x)
hand.pack(expand=YES,fill=x)
hit.pack(side=TOP,expand=YES,fill=x)
stay.pack(side=TOP,expand=YES,fill=x)
betscl.pack(side=RIGHT,expand=NO,fill=Y).set(5)
save.pack(side=BOTTOM,expand=YES,fill=Y)
bank.pack(side=BOTTOM,expand=YES,fill=Y)
load.pack(side=BOTTOM,expand=YES,fill=Y)
###########MAINPROGRAM##################
x=51
y=14
for i in range(5):
  deck[i]=c.create_image(x,y,image=deck)
  x=x+3
x=int()
y=int()
while stay == 0:
  ut = computate(userhand)
  ct = computate(comphand)
  drawbox2['text']="Your hand value is"+ut

Thanks for your help!

picme3=(PhotoImage(file="table.gif"))

(I think (I) (Might) ((See) A Problem) (Here)

wait... maybe not... I'm so confused now... why do you have the extra ()?

(I think (I) (Might) ((See) A Problem) (Here)

This is improper syntax, you're missing a closing parenthesis ;)

No but seriously, to the OP: the error you are getting is trying to tell you that the image file that you're trying to open doesn't exist. You need to check your current working directory during runtime and verify that the file is located within the same directory

import os

os.getcwd()

If it is not, you'll need to provide the entire path to the file name in order to use it. That or change your current working directory. And yes, it looks like perhaps having those parenthesis around your assignment might have something to do with it.

commented: Why didn't I catch this... +1

Thank you all for your help. I have been bug hunting and it is getting close to finished. A few redundant infinite loops here and there and I am almost done.

I will reply again should I need more help!

I have seen this problem when using Tkinter with iPython in Canopy. In my case, the code and file reference were correct, but the file reference had been incorrect on a previous run. The error state was retained between executions and the TclError: pyimge## error incremented the ## with each execution, even though the file reference was repaired.

Solution: Comment out the call to create_image() and execute. Close all the Tkinter instances that open, built up in some state-retaining buffer. Once the code (with create_image() commented out) behaved as I expected, I uncomment the create_image() call and everything works fine.

Thanks for solving this longstanding problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.