[Tutor] problem clearing a text widget

boB Stepp robertvstepp at gmail.com
Thu Sep 12 22:49:13 EDT 2019


On Thu, Sep 5, 2019 at 1:51 AM Chris Roy-Smith
<chris_roysmith at internode.on.net> wrote:

> > from tkinter import *
> >
> > def InsertText():
> >      tfield.insert(END,"Demo only\n")
> >
> > def DeleteText():
> >      tfield.delete(0,END)
> >
> > master=Tk()
> >
> > tfield = Text(master, height=15, width=60)
> > S=Scrollbar(master)
> > tfield.configure(yscrollcommand=S.set)
> > S.configure(command=tfield.yview)
> > S.grid(row=0, column=2)
> > tfield.grid(row=0, column=0, columnspan=2)
> > S.config(command=tfield.yview)
> > tfield.config(yscrollcommand=S.set)
> >
> > Button(master, text="Insert", command=InsertText).grid(row=5, column=0)
> > Button(master, text="Delete", command=DeleteText).grid(row=5, column=1)
> > Button(master, text="Exit", command=master.destroy).grid(row=5, column=2)
> >
> > master.mainloop()

> Never mind, the penny just dropped! The zero should be "0.0".

Actually shouldn't that be "1.0"?  Tkinter indexes lines of test
widgets starting with 1 not 0.  However, characters on a row/line
start with an index of 0!  See
https://web.archive.org/web/20190212094653/http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-index.html

I presume you successfully tested your code with "0.0", so what
trouble you might get into using that instead of the documented "1.0"
I have no idea...


-- 
boB


More information about the Tutor mailing list