1

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()
5
  • Could you elaborate on the problem you're having? Code snippets, the error in question? Commented Oct 4, 2010 at 3:50
  • 1
    Yes, there are hundreds of thousand of eyes just waiting here to help you out. Currently, they're all blind :-) Commented Oct 4, 2010 at 3:53
  • 1
    @pax maybe time for psychicoverflow? Commented Oct 4, 2010 at 3:56
  • Sorry guys, I accidentally hit enter before meaning to. I'm stunned at the speed of response. I figured I'd fix it before anyone noticed. Commented Oct 4, 2010 at 4:00
  • And there are : in the right places (I think) Commented Oct 4, 2010 at 4:00

1 Answer 1

3

The line:

W = Label(main, text = "No, It's "+str(states[state])

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.