467,907 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

tkinter, editing an entry, int-value of insert?

in this program when using the "c"-button it deletes the last token
entered. i want to delete the token after the mousecursor.

lets say the string is: 12*(81**.5+12) and i put the cursor between
the * and * because i want times .5 not root.
now if i press "c" it deletes ")" which is not what i want. ive tried
coming up with a function that does what i want
but neither of the ways as shown below works.
i want to do something like e.delete(INSERT, INSERT+1) but that doesnt
work because it is string+int and
INSERT+"1" doesnt work either. so how do i get the int-value of
what is the trick?
def Backspace():
#e.delete(INSERT, END)

from __future__ import division
import Tkinter
from Tkinter import *

mygui = Tkinter.Tk()


e = Entry(mygui)
e.grid(row=1, column=1, columnspan=4, sticky=NSEW)

c = Entry(mygui)
c.grid(row=2, column=1, columnspan=4, sticky=NSEW)

def Disp(nstr):
e.insert(INSERT, nstr)

def Calc():
c.delete(0, END)
c.insert(END, eval(expr))
c.insert(END, "Not computable")

def Erase():
c.delete(0, END)

def Backspace():

x = 1
y = 4
for char in '123+456-789*0()/.':
b = Button(mygui, text=char, command=lambda n=char:Disp(n),
width=2, height=1)
b.grid(row=y, column=x, sticky=NSEW)
if x==5:

b = Button(mygui, text="^", command=lambda n="**":Disp(n), width=2,
b.grid(row=8, column=2, sticky=NSEW)
b = Button(mygui, text="C",command=Erase, width=2, height=1)
b.grid(row=8, column=3, sticky=NSEW)
b = Button(mygui, text="c",command=Backspace, width=2, height=1)
b.grid(row=8, column=4, sticky=NSEW)
b = Button(mygui, text="=",command=Calc, width=18, height=1)
b.grid(row=9, column=1, columnspan=4, sticky=NSEW)

Jun 27 '08 #1
  • viewed: 2820
1 Reply
solved this:

def Backspace():
st = e.index(INSERT)
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas NŁcker | last post: by
7 posts views Thread by William Gill | last post: by
3 posts views Thread by Matt Hammond | last post: by
3 posts views Thread by William Gill | last post: by
2 posts views Thread by Martyn Quick | last post: by
1 post views Thread by Michael Yanowitz | last post: by
3 posts views Thread by dwelch91 | last post: by
reply views Thread by Leonhard Vogt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.