> i am creating a GUI in Tcl/Tk using a multitude of lines. For the
>placement of these lines, i am using small individual canvases for
>each. (This is to ensure that i can perform color changing of each
>line independent of the other based on some conditions.)
Are you aware of the tag mechanism? It would surely be better to
put all the lines on one canvas (thereby allowing easy addition
of scrollbars, for example, if you need them).
> when i am using "grid" to pack all these canvases, the lines look
>discontinuous. i was able to align the lines properly but at the
>canvas boundaries, the lines are discontinuous. is there any way to
>correct it?
My guess is that you have not disabled the highlight border.
Try reconfiguring your canvas widgets to have no highlight
border:
.c config -highlightthickness 0
But please reconsider your decision to have one canvas per line...
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
hi,
as i am a beginner in this field, i am not sure of the different
possibilities which i have while creating a GUI. i would prefer having
a single canvas rather than an entire set of canvases. let me brief
you about my requirement. i need to have a widget connected to a set
of lines. when we configure the widget, i need to change the line
colors accordingly (pls note that this is done for individual lines
and not collectively).can u pls guide me in how i can use the tag
mechanism for identifying the lines.
> as i am a beginner in this field, i am not sure of the different
>possibilities which i have while creating a GUI.
The man page for canvas is a good start :-) and the book
"Practical Programming in Tcl/Tk" is great when you are
ready for some more sophisticated ideas.
> i would prefer having
>a single canvas rather than an entire set of canvases. let me brief
>you about my requirement. i need to have a widget connected to a set
>of lines. when we configure the widget, i need to change the line
>colors accordingly (pls note that this is done for individual lines
>and not collectively).can u pls guide me in how i can use the tag
>mechanism for identifying the lines.
canvas .c
pack .c
.c create line 10 10 100 100 -tag {first_line doodle}
.c create line 10 50 100 20 -tag {second_line doodle}
.c itemconfigure first_line -fill red
.c itemconfigure second_line -fill yellow
after 5000 {.c move doodle 150 100}
Note that I gave each line a list of two tags. That
allows me to refer to each line individually by one
of the tag names, but also to use the second tag
name to talk about both lines together (in my example,
I moved both lines after a 5 second time delay).
The lines also have an identifying number, which is
returned from the ".c create" command; you can use that
number to refer to an item if you prefer.
hth
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
If what you mean by "lines" is actually "lines of text", then the
simplest way of displaying them and controlling their color, font,
etc, is just to use a single text widget, and text tags to identify
ranges of characters (here lines) and manipulate their attributes
individually. Experiment with this in an interactive wish:
text .t
pack .t
.t insert end UYTUYTUYT\n foo1
.t insert end HGJHGJHJHGJG\n foo2
.t insert end CVXVCXVCXVCXVCXV\n foo3
The above code just populates the widget with three lines of random
text, and more importantly defines tags foo1, foo2, and foo3 as the
ranges of the three lines.
Then you can switch the second line to red with
.t tag configure foo2 -foreground red.
Now if initially you meant "graphical lines", you should use a single
canvas, create lines as individual items, and either itemconfigure
them directly, or use canvas tags if some kind of grouping makes sense
and you want to change their color by group. Tell us more.
-Alex
>If what you mean by "lines" is actually "lines of text"
That hadn't occurred to me - thanks :-)
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
> hi,
> as i am a beginner in this field, i am not sure of the different
> possibilities which i have while creating a GUI. i would prefer having
> a single canvas rather than an entire set of canvases. let me brief
> you about my requirement. i need to have a widget connected to a set
> of lines. when we configure the widget, i need to change the line
> colors accordingly (pls note that this is done for individual lines
> and not collectively).can u pls guide me in how i can use the tag
> mechanism for identifying the lines.
>
set tags [ list group1 group2 groupn ]
# you get a uniq id from creation
# and you can attach "tags" to elements ( during creating or afterwards )
set uniqid1 [ $canvas create line $coords -tag $tags -fill blue ]
set uniqid2 [ $canvas create line $coords -tag nogroup -fill blue ]
# change items via the uniq id ( which is actually just another tag )
$canvas itemconfigure $uniqid1 -fill red
# change items via attached tag
$canvas itemconfigure nogroup -fill yellow
# you can search for specific tags ( or logical combinations of tags )
set elements [ $canvas find withtag {nogroup} ]
see the wiki for examples:
http://wiki.tcl.tk/14082
http://wiki.tcl.tk/_search?_charset_=utf-8&S=tags
uwe
A table might have advantages:
- You can designate one or more lines at the top as header which get a
different color (ok, also no big deal with a canvas).
- If the number of your lines grows you will need scrolling. With a
table the header lines will stay in sight, only the data lines will
scroll - using a canvas you will have to implement this yourself.
- Who knows, if the number of your lines grows maybe you want them
numbered? A trivial thing to do with a table: add a column.
Just my 0.02
Helmut Giese
hi,
the tip for placement of line segments worked fine for me.
thanks. but now i have a problem regarding the placement of the
widgets associated with the line segments within the canvas. i tried
using grid to arrange the widgets but am obtaining everything aligned
to the center of the canvas window. how can i distribute it towards
the sides as well.
i need a structure somewhat like this:
|------------------|
-----------------| |
| |-----------------------
-----------------| |
| |
-----------------| |
|------------------|
the rectangle structure shown above is my widget.there needs to be
replications of this entire structure on the canvas. how should i
arrange the structures row-wise uniformly throughout the canvas?
If you are drawing lines on a canvas and expecting them to connect or
line up with widgets, don't use "grid", "pack" or "place" to add the
widgets to the canvas. Use the canvas window object which gives you
precise control of where the widgets are placed. Plus, they will
scroll with the other objects in the canvas if you have more items
than will fit on the visible area of the canvas.
Documentation can be found here: http://tcl.tk/man/tcl8.5/TkCmd/canvas.htm#M159
> hi,
> the tip for placement of line segments worked fine for me.
> thanks. but now i have a problem regarding the placement of the
> widgets associated with the line segments within the canvas. i tried
> using grid to arrange the widgets but am obtaining everything aligned
> to the center of the canvas window. how can i distribute it towards
> the sides as well.
> i need a structure somewhat like this:
>
> |------------------|
> -----------------| |
> | |-----------------------
> -----------------| |
> | |
> -----------------| |
> |------------------|
>
> the rectangle structure shown above is my widget.there needs to be
> replications of this entire structure on the canvas. how should i
> arrange the structures row-wise uniformly throughout the canvas?
If you are putting things on a canvas (including the widgets) you should
NOT use a geometry manager (grid/pack/place). use the canvas create window
options - you can then add tag just like with your lines, plus all the coords
match so you can make sure the lines/widgets do what you want, and you can put
them wherever you want.
Bruce