tkinter, overwrite Label-text?

skanemupp at skanemupp at
Thu Apr 10 16:37:08 CEST 2008

On 10 Apr, 16:29, "Dennis.Benzin... at"
<dennis.benzin... at> wrote:
> On Apr 10, 3:47 pm, skanem... at wrote:
> > [...]
> > i use the Label-widget.
> Then you should be able to connect a variable to your widget like I
> wrote in my previous post.
> Just try out the example from the Python documentation. Of course in
> your case entrythingy would be the
> Label-widget. Take care to assign values to your variable by using the
> set function.
> Dennis Benzinger

i know how to do this already. the problem is i want the text to stay
in the windowa nd not start overwriting "Answer:".
i have solved this by using an Entry for the answer as well but id
prefer using a Label.

here is the code:

from __future__ import division
import Tkinter
from Tkinter import *

mygui = Tkinter.Tk()

l = Label(mygui, text="Answer: "), rely=0.2, anchor=CENTER)

e = Entry(mygui), rely=0.1, anchor=CENTER)

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

def Calc():
        b = Label(mygui, text=eval(expr)), rely=0.2, anchor=CENTER)
        b = Label(mygui, text="Not computable"), rely=0.2, anchor=CENTER)

def Erase():

x = 0.1
y = 0.4
for char in '123+456-789*0()/.':
    b = Button(mygui, text=char, command=lambda n=char:Disp(n),
width=2, height=1), rely=y, anchor=CENTER)
    if x==0.5:

b = Button(mygui, text="^", command=lambda n="**":Disp(n), width=2,
height=1), rely=0.8, anchor=CENTER)
b = Button(mygui, text="C",command=Erase, width=2, height=1), rely=0.8, anchor=CENTER)
b = Button(mygui, text="=",command=Calc, width=2, height=1), rely=0.8, anchor=CENTER)


More information about the Python-list mailing list