[Tutor] Printing in the same place

Alan Gauld alan.gauld at btinternet.com
Thu Aug 18 01:43:50 CEST 2011


On 17/08/11 23:20, brandon w wrote:

> I guess I will have to find another way to create a digital clock in a
> tkinter window.

The point about a GUI is that you display widgets that have text on 
them. It could be a Label, or a Button or a Text box or even a Canvas.
Then to change the text you simply replace the text en-masse with a new 
string, you don't attempt to backspace or return or anything like you 
would with print(). (Actually with a Text box widget you could do that 
by controlling the cursor, but for your purpose that is just making it 
harder than it needs to be!)

You just assign a new string to the widgets text attribute.

You can see how to do that with one of the examples on my GUI tutor.
It replaces the text on a label with the contents of an entry box:


# create the event handler to clear the text
def evClear():
   lHistory['text'] = eHello.get()
   eHello.delete(0,END)


the label(lHistory) simply displays whatever is assigned to its text 
attribute, and in this case its whatever is in the Entry widget (eHello) 
before we clear it. It could just as well be a string displaying the 
current time...

HTH,

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list