# [Tutor] Tkinter draw line segments

Phil phillor9 at gmail.com
Wed Mar 30 19:17:21 EDT 2022

```On 31/3/22 03:21, Peter Otten wrote:
> On 30/03/2022 17:27, Peter Otten wrote:
>
>> I'd go about it a bit differently. When you draw all segments separately
>> you can remember them by their ids. To display the desired digits you
>> can hide/display segments as needed. A complete example:

Thank you Peter and Dennis, once again you've given me something to

I abandoned my initial design and this is how I managed to solve the
problem:

seg = {0: (20, 20, 40, 20),
1: (44, 24, 44, 44),
2: (44, 48, 44, 68),
3: (20, 72, 40, 72),
4: (16, 48, 16, 68),
5: (16, 24, 16, 44),
6: (20, 46, 40, 46)
}

digits = {0: ('lime', 'lime', 'lime', 'lime', 'lime', 'lime', 'black'),
1: ('black', 'lime', 'lime', 'black', 'black', 'black', 'black'),
2: ('lime', 'lime', 'black', 'lime', 'lime', 'black', 'lime'),
3: ('lime', 'lime', 'lime', 'lime', 'black', 'black', 'lime'),
etc

Inside an after loop I have:

for i in range(7): # yes I know I should use for s in seq. It's
a hard-to-break habit
self.canvas.create_line(seg[i], width=4,
fill=digits[number][i])

number is incremented every second.

The digits are displayed on a black rectangle and, even if I say so
myself, the result is quite realistic.

>
> Shortly after hitting send I had a Eureka moment: use tags!

I've not come across tags until now so that'll probably keep me busy for
the rest of the day.

--

Regards,
Phil

```