I am teaching myself some Python and I have come across a problem which is probably plainly obvious, except that I can’t see it and I need another pair of eyes.
I am making a small game I made into a gui program.
I have this section of code, which when run gives me
“Traceback (most recent call last):
File “”, line 21, in
Syntax Error: if playguess == “A”:: , line 2124″
Line 21 being if playguess == “A”:
There may be a couple unrelated things wrong, but it’s the IF statement that is baffling me right now.
I have imported the Tkinter module, I just copied the part that I thought was relevant.
def compare():
R = Label(main, text = 'Yes you are right !')
W = Label(main, text = "No, It's "+str(states[state])
#if playerguess == str(states[state]):
if playguess == "A":
R.pack()
else:
W.pack()
#print ("Guess State Capitols")
state = choosestate()
main = Tk()
main.title("Guess State Capitols")
main.geometry('450x100+200+100')
Q = Label(main,text = 'What is the capitol of ' +state)
Q.pack()
playerguess = Entry(main)
playerguess.pack()
playguess = playerguess.get()
main.mainloop()
The line:
Doesn’t have a closing parentheses for the Label() class/function.
Therefore, the if statement is interpreted as being inside parentheses, which doesn’t work.