[Tutor] help with tkinter?

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 21 Mar 2001 09:17:59 -0800 (PST)


On Wed, 21 Mar 2001, doc pepin wrote:

> i've made a timer program with python and tkinter but
> the problem is i don't know how to display the result
> or output on the main window and not on the console.

Hmmm... I believe you should be able to use the Label widget with a
StringVar, which will let you change the Label's contents on the fly.  For
example:


###
from Tkinter import *

root = Tk()

s = StringVar()
s.set("Hello World")
Label(textvariable = s).pack(side=LEFT)

def rotate(svar = s):
    mystr = s.get()
    s.set(mystr[1:] + mystr[0])

Button(text="Press me to rotate the label",
       command=rotate).pack(side=LEFT)

mainloop()
###


However, there might be a better way of doing this; I haven't gotten past
StringVars yet.

Hope this helps!