By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

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

P: 4
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:

Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2.  
  3. def evclr():
  4.     chatsend.delete(0,END)
  5.  
  6. def chat(user, items, userslist):
  7.     global chatsend
  8.  
  9.     v0 = Tkinter.Tk()
  10.     v0.geometry('450x250+100+100')
  11.     v0.title('J+ CHATTING ROOM Welcome')
  12.     chat_msg = Tkinter.StringVar()
  13.  
  14.     chatwindow = Tkinter.Text(v0, height=12, width=55)
  15.     chatwindow.insert(Tkinter.INSERT, chat_content)
  16.     chatwindow.pack()
  17.  
  18.     chatsend = Tkinter.Entry(v0, bd=3, textvariable=chat_msg).pack()
  19.  
  20.     sendbutton = Tkinter.Button(v0, text='SEND', command=evclr).pack()
  21.  
  22.     v0.mainloop()
  23.  
  24.  
  25. chat_content = '''
  26.       Tue 07 Apr 2015
  27.   12:11:25 
  28. X> ===}
  29. ===
  30. '''
  31.  
  32. chat('X', [0, 2], ['CARLOS VILLALOBOS', 'CESAR BENCOMO', 'JOHNNY CASH'])
  33.  
and this is what i get:

Expand|Select|Wrap|Line Numbers
  1. Exception in Tkinter callback
  2. Traceback (most recent call last):
  3.   File "C:\Python27\64\lib\lib-tk\Tkinter.py", line 1532, in __call__
  4.     return self.func(*args)
  5.   File "C:/Python27/Scripts/prueba04.py", line 13, in evclr
  6.     chatsend.delete(0,END)
  7. AttributeError: 'NoneType' object has no attribute 'delete'
  8. Exception in Tkinter callback
  9. Traceback (most recent call last):
  10.   File "C:\Python27\64\lib\lib-tk\Tkinter.py", line 1532, in __call__
  11.     return self.func(*args)
  12.   File "C:/Python27/Scripts/prueba04.py", line 13, in evclr
  13.     chatsend.delete(0,END)
  14. AttributeError: 'NoneType' object has no attribute 'delete'
Apr 7 '15 #1

✓ answered by bvdet

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.

Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
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.
Apr 7 '15 #2

P: 4
Thanks so much, i really apreciate your help and time spent
Apr 7 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.