Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Projects for Kids

You're reading from  Raspberry Pi Projects for Kids

Product type Book
Published in Mar 2014
Publisher
ISBN-13 9781783982226
Pages 96 pages
Edition 1st Edition
Languages
Author (1):
Daniel Leonard Bates Daniel Leonard Bates
Profile icon Daniel Leonard Bates

Adding labels


It would be useful if whenever we clicked on the map, along with adding a circular marker, we could also add a few words to describe what it is we're marking.

Basic labels

Getting some text from the program's user is going to be slightly complex, so let's create a simple version first to make sure we have the right code structure. Add the following two lines of code right at the end inside the canvasclick function:

    label = getlabelname()
    widget.create_text(x, y+2*size, text=label)

The first line of code gets some text from a function that we haven't written yet called getlabelname. This function will eventually ask the user to type some text into a small pop-up window, but for now, it will just give us a default message. The second line of code draws our text at a particular position just underneath the circle. As with widget.create_oval earlier, widget.create_text allows the text color to be set using the extra arguments of fill="colour" and activefill="colour".

Here is...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}