Python Forum
Problem with tkinter and string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with tkinter and string
#1
Code:

from tkinter import *
import random
from tkinter.messagebox import*
def checking():
outPut=10
overLap=Label(text=outPut)
overLap.place(x=200,y=100)
stringForChecking=str(inputForLetters.get())#ERROR
print(stringForChecking)
answer=str(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 funkcije
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=str(word.get())#ERROR
AttributeError: 'str' object has no attribute 'get'
Reply


Messages In This Thread
Problem with tkinter and string - by Dule - May-25-2019, 04:55 PM
RE: Problem with tkinter and string - by joe_momma - May-25-2019, 05:45 PM
RE: Problem with tkinter and string - by Dule - May-25-2019, 05:51 PM
RE: Problem with tkinter and string - by Yoriz - May-25-2019, 11:25 PM
RE: Problem with tkinter and string - by Dule - May-26-2019, 05:17 AM
RE: Problem with tkinter and string - by Yoriz - May-26-2019, 10:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,745 Feb-17-2022, 07:02 AM
Last Post: pymn
  Python3 tkinter radiobutton problem Nick_tkinter 14 6,627 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  tkinter python button position problem Nick_tkinter 3 3,802 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] ClockIn/Out tkinter problem Maryan 2 2,386 Oct-12-2020, 03:42 AM
Last Post: joe_momma
  tkinter| listbox.insert problem Maryan 3 3,777 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  Tkinter problem DPaul 6 4,407 May-28-2020, 03:40 PM
Last Post: DPaul
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 2,722 Apr-17-2020, 08:12 PM
Last Post: johnjh
  [Tkinter] Problem with tkinter when creating .exe file Jan_97 2 4,810 Feb-27-2020, 05:17 PM
Last Post: Jan_97
  [Tkinter] Tkinter problem catlessness 1 2,157 Jan-15-2020, 05:17 AM
Last Post: Larz60+
  Problem with Submit button Tkinter Reldaing 2 3,818 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020