472,958 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

clearing text on canvas

hi
i am new to tkinter and would like some help with canvas

i am doing validation of contents of a folder and need to show the
ok/error messages on a canvas

resultdisplay =Canvas(...)
errmessage="error!"
okmessage="dir validation ok!"

if dirvalidate is False:
resultdisplay.create_text(1,50,anchor=W,text=errme ssage,width=175)

else:
self.resultdisplay.create_text(1,50,anchor=W,text= okmessage,width=175)
my problem is that if validation succeeds or fails the text created on
canvas is displayed over the previous created text
I need to clear the previous text from the canvas before creating new
text
can someone help?
dn

Dec 18 '07 #1
2 5414
de****@gmail.com wrote:
i am doing validation of contents of a folder and need to show the
ok/error messages on a canvas

resultdisplay =Canvas(...)
errmessage="error!"
okmessage="dir validation ok!"

if dirvalidate is False:
if ... is False: ...

is bad style. Just

if dirvalidate: ...

reads better and is less likely to cause subtle errors.
resultdisplay.create_text(1,50,anchor=W,text=errme ssage,width=175)

else:
self.resultdisplay.create_text(1,50,anchor=W,text= okmessage,width=175)
my problem is that if validation succeeds or fails the text created on
canvas is displayed over the previous created text
I need to clear the previous text from the canvas before creating new
text
can someone help?
You create the text once but keep its handle for further changes.

handle = canvas.create_text(...)

You can change it later with

canvas.itemconfigure(handle, ...)

Here's a short self-contained example:

import Tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root, width=100, height=100)
canvas.pack()

text_id = canvas.create_text(50, 50, width=100)

ok = False
def change_text():
global ok
ok = not ok
if ok:
text = "ok"
else:
text = "error"

canvas.itemconfigure(text_id, text=text)

button = tk.Button(root, text="change text", command=change_text)
button.pack()

root.mainloop()

Peter
Dec 19 '07 #2
thanx a lot Peter
dn
Dec 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gary Richardson | last post by:
I've been working on a Python version of Andreas Weber's ASCII schematic drawing program ( http://www.tech-chat.de) ; not that I thought I could do it better but just as a programming exercise....
4
by: Peter Otten | last post by:
Is there a way to limit both width and height of a canvas text item? My current workaround seems clumsy: import Tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, width=400, height=200,...
2
by: Billy | last post by:
Hi, This is in connection to the tread: Re: changing browser text settings?? I am wondering if there is a way to retrieve the browsers text size (not change! ;-) ) so that I can dynamically...
6
by: mphanke | last post by:
Hi, I'm desperately trying to print a string on top of an image, but for whatever reason the images allways stays on top of my canvas! Is there some trick how to implement things? I call ...
4
by: Dragon | last post by:
Hi, Does anyone know of any examples for writing text into images? I have a program that collects some system information and I would like to write that text into a BMP or JPG file. Thank you.
7
by: Michael Galvin | last post by:
I am trying to use Python to send to the printer a calender filled with a mix of text and simple graphics. I want to draw on the printed page something like a table with 6 rows and 7 columns to...
5
by: deacon.sweeney | last post by:
Hi, I've been searching for a .resize()-like function to overload much like can be done for the delete window protocol as follows: toplevel.protocol("WM_DELETE_WINDOW", callback) I realize...
6
by: Nebulism | last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from...
2
by: almurph | last post by:
Hi, Hope you can help me with one please. I import an image and display it on a picture box control. I then have functionality change its size (code included below). Now I need to add some text...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.