473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

tkinter canvas tag stuff

I'm trying to display a picture on a Tkinter Canvas. It seems to work
fine the first time that it is displayed. However, subsequent times
running shows an error like this:

TCLerror: Wrong # args: should be ".-1211472948 .-1211470996 addtag tag
searchCommand ?arg arg ...?

My code works like this:

if (pic):
canvas.delete(pic)
im=Image.open(path)
image=ImageTk.PhotoImage(im)
pic=canvas.create_image(1,1,anchor="nw", image=image)
canvas.addtag(pic)
Note that path is a path selected outside of the function. What happens
is the image is displayed, but with the error message. I think I should
either have to put in some kind of argument into the addtag, which
isn't documented well, or use a similar but different function. Thanks
for the help!

Dec 16 '05 #1
3 4454
Tuvas wrote:
I'm trying to display a picture on a Tkinter Canvas. It seems to work
fine the first time that it is displayed. However, subsequent times
running shows an error like this:

TCLerror: Wrong # args: should be ".-1211472948 .-1211470996 addtag tag
searchCommand ?arg arg ...?

My code works like this:

if (pic):
canvas.delete(pic)
im=Image.open(path)
image=ImageTk.PhotoImage(im)
pic=canvas.create_image(1,1,anchor="nw", image=image)
canvas.addtag(pic)
Note that path is a path selected outside of the function. What happens
is the image is displayed, but with the error message. I think I should
either have to put in some kind of argument into the addtag, which
isn't documented well, or use a similar but different function. Thanks
for the help!


There are at least 2 better (more common, and thus closer the the "one--
and preferably only one") ways to do this.

1. include a tag option when creating the image
pic=canvas.create_image(1,1,anchor="nw", image=imagem, tag="some_tag")
2. use the Canvas.addtag_withtag method:
canvas.add_tag_withtag('some_tag', pic)

These examples assume the tag you want to use is called "some_tag".

A brief description on the use of tags is at

http://www.pythonware.com/library/tk...ts.htm#AEN2057

BTW, the error message you are getting is an artefact of Tk. I have yet
to find any Tkinter-specific documentation on the Canvas.addtag method,
but the Tk documentation suggests the following is equivalent to the above:

canvas.addtag("some_tag", "withtag", pic)

James
Dec 16 '05 #2
Tuvas wrote:
I'm trying to display a picture on a Tkinter Canvas. It seems to work
fine the first time that it is displayed. However, subsequent times
running shows an error like this:

TCLerror: Wrong # args: should be ".-1211472948 .-1211470996 addtag tag
searchCommand ?arg arg ...?

My code works like this:

if (pic):
canvas.delete(pic)
im=Image.open(path)
image=ImageTk.PhotoImage(im)
pic=canvas.create_image(1,1,anchor="nw", image=image)
canvas.addtag(pic)
Note that path is a path selected outside of the function. What happens
is the image is displayed, but with the error message. I think I should
either have to put in some kind of argument into the addtag, which
isn't documented well, or use a similar but different function. Thanks
for the help!


I think I killed my last post trying to fix a typo. I'm very new to
using NNTP. Forgive me if this is a close duplicate to something you
already have in your inbox.

Anyway, my corrected message goes like something like this:

There are two better (more common) ways to do this:

1. Use the tag keyword argument when creating the canvas_image:
pic=canvas.create_image(1,1,anchor="nw", image=image, tag="some_tag")
2. Use the Canvas.addtag_withtag method:
canvas.addtag_withtag('some_tag', pic)

I have yet to find Tkinter-specific documentation on the Canvas.addtag
method, but the Tk documentation suggests this has the same affect as above:

canvas.addtag("some_tag", "withtag", pic )

James
Dec 16 '05 #3
It's funny, I can put in more variables than needed, it doesn't even
call the function, and yet, magically, the picture appears. Odd... Just
wish I could solve the problem...

Dec 20 '05 #4

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

Similar topics

2
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
2
by: Michael Zhang | last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images from server and display those images. I created a thread (also a separate toplevel window) for displaying images and another...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
5
by: annagel | last post by:
I am looking for a way to force a Tkinter window into focus on a system level. I know the force focus method should bring one window of my application into focus, but it seems I need to have some...
32
by: Kevin Walzer | last post by:
I'm a Tcl/Tk developer who has been working, slowly, at learning Python, in part because Python has better support for certain kinds of applications that I want to develop than Tcl/Tk does....
4
by: D | last post by:
I'm sure this is a simple question to the Tkinter experts - I have a very basic Tkinter application that consists of 1 master window and buttons within that window. My problem is that, I need to...
4
by: Davy | last post by:
Hi all, I have written a simple Tkinter program, that is draw a rectangle in a canvas, when I press Up key, the rectangle move up. But the program seems work not properly? My environment is...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.