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="err or!"
okmessage="dir validation ok!"
if dirvalidate is False:
resultdisplay.c reate_text(1,50 ,anchor=W,text= errmessage,widt h=175)
else:
self.resultdisp lay.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 2 5691 de****@gmail.co m wrote:
i am doing validation of contents of a folder and need to show the
ok/error messages on a canvas
resultdisplay =Canvas(...)
errmessage="err or!"
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.c reate_text(1,50 ,anchor=W,text= errmessage,widt h=175)
else:
self.resultdisp lay.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_t ext(...)
You can change it later with
canvas.itemconf igure(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_t ext(50, 50, width=100)
ok = False
def change_text():
global ok
ok = not ok
if ok:
text = "ok"
else:
text = "error"
canvas.itemconf igure(text_id, text=text)
button = tk.Button(root, text="change text", command=change_ text)
button.pack()
root.mainloop()
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
I've managed to put together something that more or less works
but I'm puzzled by the way ASCII characters are displayed on a Canvas
window. For example, in the code below (which produces my crude
representation of an OpAmp), why are two leading...
|
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, bg="white")
canvas.pack()
# simulate a clipped text item - never transparent :-(
s = "The long and winding road.."
|
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 resize the size and position of the
layers to accomodate larger than normal text-size settings. I really hope
there is because it would mean not re-writing the whole page (which I'm not
sure how to go about).
the page is here:
|
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
ev.graphics.drawimage(img, rect);
ev.graphics.drawstring("mystring", ..., rect, ...);
|
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.
| |
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 represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP
I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses...
|
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 that the pack manager usually handles all of the resize
stuff, but I've found an arrangement that the pack manager fails for.
That is, if one embeds a canvas into a window created inside a text
widget, then resize the text widget (via its container),...
|
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 http://www.java2s.com/Code/Python/Event/Usemousetodrawashapeoncanvas.htm .
The code itself is:
from Tkinter import *
trace = 0
class CanvasEventsDemo:
def __init__(self, parent=None):
canvas = Canvas(width=300, height=300, bg='beige')
canvas.pack()
|
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 *not* on image but beside the image,
like an area to the side of the image say but not actually on the
image (likn on a lable that can be added to the image to form kind of
a new image).
Problem is though I dont know how to do this (in fact, I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |