0

我有一个画布 c,我在上面画了一个图形,现在我想标记图形的点。无论出于何种原因,图表都有效,但标签无效。

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')

如您所见,第一个 for 循环基本上将线绘制到它所连接的每个国家,并根据其是否属于同一大陆来选择颜色。我不确定为什么 c.create_line 有效而 c.create_text 无效

4

1 回答 1

3

在这条线上:

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

您没有指定text参数,因此不会绘制任何文本。

尝试:

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
于 2013-08-22T15:06:53.270 回答