May-25-2019, 05:51 PM
from tkinter import * import random from tkinter.messagebox import* def checking(): outPut=10 overLap=Label(text=outPut) overLap.place(x=200,y=100) stringForChecking=inputForLetters.get()#ERROR print(stringForChecking) answer=word.get()#ERROR if stringForChecking in answer: overLap=Label(text=outPut) overLap.place(x=100,y=100) else: outPut=outPut-1 overLap=Label(text=outPut) overLap.place(x=100,y=100) return() turn=0 # izbor rijeci words=['pas','mačka'] #odabir random rijeci word=(random.choice(words)) #imenovanje varijeble za skrivanje rijeci wordHidden='' #for petlja za dodavanje u wordHidden for char in word: wordHidden=wordHidden+'_' wordHidden=wordHidden+' ' #GUI #stavljane prozora t=Tk() t.config(bg='white',width=500,height=200) #label za pogadanje rijeci wordToGuess=Label(t,text=wordHidden) wordToGuess.place(x=60,y=15) #entry za pogadanje slova inputForLetters=Entry() inputForLetters.place(x=20,y=60) #label za broj preostalih pokusaja inputGuesses=Label(t,text="Preostali pukusaji: ") inputGuesses.place(x=80,y=100) #label za broj preostalih rijeci za pogodit GuessesLeft=Label(t,text="Broj preostalih rijeci: ") GuessesLeft.place(x=80,y=150) #gumb za pozivanje fnkcije if turn<10: btnForSubmiting=Button(t, text='Pogodi', command=checking) btnForSubmiting.place(x=10,y=100) else: showinfo('GAME OVER') mainloop()
Error:Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Sava\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Sava\Desktop\PyGame\igra2.py", line 10, in checking
answer=word.get()#ERROR
AttributeError: 'str' object has no attribute 'get'
Still outputs the error