Welcome to Dream.In.Code
Click Here
Getting Help is Easy!

Join 118,882 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,984 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Tkinter Syntax Error

 
Reply to this topicStart new topic

Tkinter Syntax Error, Im getting a Syntax Error where there shouldnt be one...

sandman93
post 5 May, 2008 - 02:25 PM
Post #1


New D.I.C Head

*
Joined: 26 Sep, 2006
Posts: 12


My Contributions


Okay well i started trying to learn Tkinter and i wanted to create a gui for my game i had made previously. Here is my code

CODE
from tkinter import *

class app:


    def_init_(self, master);
        
    frame = Frame(master)
    frame.pack()
    
    self.label = Label(frame, text="Would you like to play?"
    
    self.button = Button(frame, text="Yes!", command=self.play)
    self.button.pack(side=LEFT)

    self.button = button(frame, text="NO!!!", command=self.quit)
    self.button.pack(side=LEFT)

    def play(self):
        number = aStr = "dictionary"
        a = 'dictionary'
        answer = a
        answer = ''
        print'Descramble this word!!'
        print aStr[3] + aStr[6] + aStr[1] + aStr[5] + aStr[0] + aStr[9] + aStr[2] + aStr[8] + aStr[4] + aStr[7]
        attempts = 0
        while answer != number:
            attempts = attempts + 1
            answer = raw_input( '?' )
            answer = int( '' )
            if( answer > number ):
                print 'Try Again'
            elif( answer < number ):
                print 'Wrong'
            elif( answer == number ):
                print 'you got it rights in %i tries!' %(attempts)

root = Tk()

app = app(root)


root.mainloop()


ITs saying im having a syntax error here

CODE
    self.button = Button(frame, text="Yes!", command=self.play)
    self.button.pack(side=LEFT)


its saying its right on the F in the self
User is offlineProfile CardPM

Go to the top of the page


Nova Dragoon
post 5 May, 2008 - 02:36 PM
Post #2


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,015



Thanked 2 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


The line above that.

You didn't close your parens in the method call.
User is offlineProfile CardPM

Go to the top of the page

sandman93
post 5 May, 2008 - 03:20 PM
Post #3


New D.I.C Head

*
Joined: 26 Sep, 2006
Posts: 12


My Contributions


wow geez what a mistake LOL

i fixed that and some other mistakes i made but its not doing what i anticipated it to....

i got it running and it has my message there and the 2 buttons. How do i make the buttons be under the message? instead of to the side? is there some kind of command i have to put in after (side = ? )

also why does it make me go back to the CMD to input my answer? and when i input my answer it says i ahve a value error for the int on line 31?

what should i do to make the word that i want unscrambled to apear in a text box like my questions and buttons do? and have them input from there?

Thanks for the help Nova smile.gif

its now telling me that it the global name frame isnt defined on line 31 in play

CODE
from Tkinter import *

class app:


    def __init__(self, master):
        
        frame = Frame(master)
        frame.pack()
    
        self.label = Label(frame, text="Would you like to play?")
        self.label.pack(side=LEFT)
    
        self.button = Button(frame, text="Yes!", command=self.play)
        self.button.pack(side=LEFT)
    
        self.button = Button(frame, text="NO!!!", command=frame.quit)
        self.button.pack(side=LEFT)



    def play(self):

        class app:

            def __init__(self, master):
        
                frame = Frame(master)
                frame.pack()
    
        number = aStr = "dictionary"
        a = 'dictionary'
        answer = a
        answer = ''
        self.message = Message(frame, text= "Descramble this word!!")
           self.message = Message(frame, text= aStr[3] + aStr[6] + aStr[1] + aStr[5] + aStr[0] + aStr[9] + aStr[2] + aStr[8] + aStr[4] + aStr[7])        
        attempts = 0
        while answer != number:
            attempts = attempts + 1

        self.entry = Entry( )
            
        if( Entry > number ):
            print 'Try Again'
        elif( Entry < number ):
            print 'Wrong'
        elif( Entry == number ):
            print 'you got it rights in %i tries!' %(attempts)

root = Tk()

app = app(root)


root.mainloop()


This post has been edited by sandman93: 5 May, 2008 - 03:52 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 02:50AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month