How to delete an entry content after click a button (Tkinter)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carlos25
    New Member
    • Apr 2015
    • 4

    How to delete an entry content after click a button (Tkinter)

    I'm looking for a simle form to delete the entry content after pushing a button, in the next link the solution for the code works (verified it), after read that i try it, but it doesn't work for me

    http://bytes.com/topic/python/answers/867449-gui-text-entry-tkinter

    Python 2.7.9 [MSC v.1500 64 bit (AMD64)] on Windows 7 64 bits

    this is the part of code that i can't fix:

    Code:
    import Tkinter
    
    def evclr():
        chatsend.delete(0,END)
    
    def chat(user, items, userslist):
        global chatsend
        
        v0 = Tkinter.Tk()
        v0.geometry('450x250+100+100')
        v0.title('J+ CHATTING ROOM Welcome')
        chat_msg = Tkinter.StringVar()
        
        chatwindow = Tkinter.Text(v0, height=12, width=55)
        chatwindow.insert(Tkinter.INSERT, chat_content)
        chatwindow.pack()
        
        chatsend = Tkinter.Entry(v0, bd=3, textvariable=chat_msg).pack()
        
        sendbutton = Tkinter.Button(v0, text='SEND', command=evclr).pack()
    
        v0.mainloop()
    
    
    chat_content = '''
          Tue 07 Apr 2015
      12:11:25 
    X> ===í}
    éé===
    '''
    
    chat('X', [0, 2], ['CARLOS VILLALOBOS', 'CESAR BENCOMO', 'JOHNNY CASH'])
    and this is what i get:

    Code:
    Exception in Tkinter callback
    Traceback (most recent call last):
      File "C:\Python27\64\lib\lib-tk\Tkinter.py", line 1532, in __call__
        return self.func(*args)
      File "C:/Python27/Scripts/prueba04.py", line 13, in evclr
        chatsend.delete(0,END)
    AttributeError: 'NoneType' object has no attribute 'delete'
    Exception in Tkinter callback
    Traceback (most recent call last):
      File "C:\Python27\64\lib\lib-tk\Tkinter.py", line 1532, in __call__
        return self.func(*args)
      File "C:/Python27/Scripts/prueba04.py", line 13, in evclr
        chatsend.delete(0,END)
    AttributeError: 'NoneType' object has no attribute 'delete'
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    That's because method call pack() returns None. Assign the widget instance to chatsend without calling pack(), then call chatsend.pack() on the next line.

    Comment

    • carlos25
      New Member
      • Apr 2015
      • 4

      #3
      Thanks so much, i really apreciate your help and time spent

      Comment

      Working...