N
N
New_account2018-05-01 20:13:40
Python
New_account, 2018-05-01 20:13:40

How to clear text input field in tkinter?

I need to clear a text input field in tkinter. I found this solution on the Internet: entry.delete(0, END)Where entry is the name of the input field (direct link to it), 0 is the beginning of the input field string, END is the end of the input field string. This command should clear the input field from start to finish. But this error pops up:

AttributeError: 'NoneType' object has no attribute 'delete'
Who is familiar with tkinter, please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-05-01
@New_account

The method placedoes not return anything, so the line of code
assigns a entryvalue to a variable None
Correct to

entry = Entry(canvas, width=20,)
entry.place(x=150, y=300)

A
Alexander, 2018-05-01
@NeiroNx

First you need to get the field itself. You didn't receive it.
within the class:

class Application(Tk):
  def OnEnterInput(self, event):
    text=u''+self.input.get()
    self.Send(text)
    self.input.delete(0, END)
  def createWidgets(self):
.....
    self.input = Entry(self, textvariable=self.inline)
    self.input.grid(row=0, column=0, columnspan=2, pady=3, padx=3, sticky='ew')
    self.input.bind("<Return>", self.OnEnterInput)

full code here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question