Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StringVar instance has no attribute 'delete'

I am having trouble using the delete method for Entry in tkinter. Currently I import tkinter as follows:

import Tkinter as tk

I then declare two variables that are used to track the value of two entry fields as follows:

self.UN = tk.StringVar()
self.PW = tk.StringVar()

I am able to get the value using

self.UN.get() 

without any issue but when try to delete the value using

self.UN.delete(0, END)

I get the error, StringVar instance has no attribute 'delete' I have looked through other possible solutions on SO but none seem relevant to my issue. I used the following tutorial to try and get this to work: http://effbot.org/tkinterbook/entry.htm

I have also tried variations on the delete like putting Tk.END inside the brackets, but can't get this going. Any help is appreciated.

like image 273
Rob EatsEverything Delaney Avatar asked Sep 29 '22 11:09

Rob EatsEverything Delaney


1 Answers

Instead of delete(), you have to use set():

field_name.set('')

It's working from my side.

like image 103
santhana krishnan Avatar answered Oct 03 '22 02:10

santhana krishnan