Why does info exists always return 0 when checkin for the existence of a canva object (Tcl/Tk 8.5) -


I tried the following test (see snippet below):

And it always depends on 0 The fact is that the canvas object (rectangle in this case) has been made (with "make") or removed (with "delete").

Whether the canvas object is present or has not been successfully removed in TCL / TC?

Thank you!

Serge Hulan

  ############ tk:: canvas Set r1 [.ec 30 10 120 80-line to create #fb0 -fill # fb0] set r2 [.com can rect 150 10 240 80-lineline # f 50 -fil # f50] set r3 [ . Rect 270 10 370 80-line # 05f -fill # 05f] Pack. ## ## Information for Canvas Elements Exists: It always puts the RCC [information is $ R2] "RCC = $ RCC" {[Info is $ R2 exists}} {puts "$ r2 exists is!" $ R2 puts [Info $ R2 exists]} Delete {puts "$ R2 does not exist!" Set RC [Insert $ R2] puts "RC = $ RC"} #### wm Heading "Color" wm geometry 400x100 + 300 + 300 ##########   

information exists is used to check whether Whether the variable exists or not the canvas widget is not a variable, it's an widget .

In this way, you need to check whether the canvas exists or not:

  Winfo exists.  

But again, what you use in your code as r2 is an object within the canvas, and to check it out Order is not existed As far as I know, you can use . :

  To get a list of all items in this canvas, you can create the % Tk :: canvas.can% set r1 [.crct 30 10 120 80-lineline Are #fb0fill #fb0]% set r2 [.cpt 150 10 240 80-lineline can be made #f50fil #f50]% set r3 [Rect 270 10 370 80-line # 05f -fil # 05f]% to make $ $ 2 r2 = because it's made of second item%. All 1 2 3  

then you can do something like lsearch -exact [you can find everything] $ r2 and if you do not get anything then -1 , know that this item exists.


Although you use unique tags with your item, you can use . Find out withtag to verify its existence

 % tk:: canvas.can% set r1 [.crct 30 10 120 80-line line #fb 0 -fill # fb0 -tags t1 ]% Can set R2. [Rect 150 10 240 80-line line can be made # f50 -fill # f50 -tags T2]% set R3 [. 270 10 370 80 -line # 05f -fill # 05f -tags t3]% to create a cache. Withtag t2 2 # that is equal to $ r2  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -