469,294 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,294 developers. It's quick & easy.

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:

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.

2 7158
bvdet
2,851 Expert Mod 2GB
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
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.

Similar topics

reply views Thread by [Yosi] | last post: by
5 posts views Thread by Steve | last post: by
12 posts views Thread by Thammarat charoenchai. | last post: by
5 posts views Thread by laziers | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.