0

I have a canvas c that I drew a graph on, and now I want to label the points of the graph. For whatever reason, the graph is working, but not the labels.

countries = starcoords.keys() #returns a list of all the countries I want to work with
for i in countries: #this part works
    (xcor1, ycor1) = starcoords[i][1] #basically, returns the coordinates of the country i'm working with
    for j in starcoords[i][2]: #starcoords[key][2] is a list of all the countries it connects to, then it goes through and draws lines to each country
        (xcor2, ycor2) = starcoords[j][1]
        if starcoords[i][0] == starcoords[j][0]:
            continent = starcoords[i][0]
            continentcolour = clustercoords[continent][0]
            c.create_line(xcor1, ycor1, xcor2, ycor2, fill=continentcolour,width=2, activefill='#900')
        else:
            c.create_line(xcor1, ycor1, xcor2, ycor2, fill="grey",width=2,activefill='#900')

for i in countries: #for whatever reason this part doesn't
    (xcor1, ycor1) = starcoords[i][1]
    print(xcor1,ycor1)
    c.create_text(xcor1, ycor1,fill='grey')

as you can see, the first for-loop basically draws lines to each country it is connected to, and selects the color based on whether its part of the same continent. I'm not sure why c.create_line is working and c.create_text is not

1
  • Your indentation is incorrect. How do we know if that second for i loop is part of the function or part of something else (or part of the other for loop...)? Commented Aug 22, 2013 at 15:25

1 Answer 1

3

On this line:

c.create_text(xcor1, ycor1,fill='grey')

You do not specify a text argument, so no text is drawn.

Try:

for i in countries:
    (xcor1, ycor1) = starcoords[i][1]
    c.create_text(xcor1, ycor1,fill='grey', text=i) 
    #...assuming `i` is a string containing the name of the country
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.