#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Tkinter Help - Having trouble binding functions to Widgets


    Hello,
    I'm a Tkinter noob and looking to get some help. I'm getting this error:
    'Traceback (most recent call last):
    File "/home/haydn/Documents/Aptana Studio 3 Workspace/Grammar Nazi 1.0/SS.py", line 36, in <module>
    app = grammarNazi(None)
    File "/home/haydn/Documents/Aptana Studio 3 Workspace/Grammar Nazi 1.0/SS.py", line 7, in __init__
    self.initialize();
    File "/home/haydn/Documents/Aptana Studio 3 Workspace/Grammar Nazi 1.0/SS.py", line 14, in initialize
    preposition=Tkinter.Button(self, text=u"Check Prepositions", command=self.prepositionPress)
    File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __getattr__
    return getattr(self.tk, attr)
    AttributeError: prepositionPress

    when I run this code:
    Code:
    import Tkinter
    
    class grammarNazi(Tkinter.Tk):
        def __init__(self,parent):
            Tkinter.Tk.__init__(self,parent);
            self.parent=parent;
            self.initialize();
            
        def initialize(self):
            self.grid();
       
            preposition=Tkinter.Button(self, text=u"Check Prepositions", command=self.prepositionPress)
            preposition.grid(column=0, row=1)
            
            splitInfinitive=Tkinter.Button(self, text=u"Check Split Infinitives")
            splitInfinitive.grid(column=1,row=1)
    
            self.inputVariable = Tkinter.StringVar()
            self.input=Tkinter.Entry(self,textvariable=self.inputVariable)
            self.input.grid(column=0, row=0, columnspan=2, sticky='NESW')
        
            self.output=Tkinter.Text(self)
            self.output.grid(column=0, row=2,columnspan=2, sticky='NESW')
            
            def prepositionPress(self):
                print self.inputVariable.get();
            
    if __name__=="__main__":
        app = grammarNazi(None)
        app.title('Grammar Nazi 1.0')
        app.mainloop()
    Any help would be appreciated.

    Edit: Sorry, messed up my indentation...I see it now -.-
    Thanks Anyway
    Last edited by franklyn1234; May 15th, 2013 at 06:09 PM. Reason: Fixed
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    For followers...correction pertains to
    Code:
            def prepositionPress(self):
                print self.inputVariable.get()
    Note that semi-colon separates statements. Not required to end statements.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo