2013-08-22 56 views
0

我有一張畫布c,我畫了一張圖,現在我想標註圖的點。無論出於何種原因,圖表正在工作,但不是標籤。Tkinter in python-爲什麼我不能創建文本?

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不

+0

你的縮進不正確。我們如何知道第二個'for i'循環是功能的一部分還是其他功能的一部分(或者循環的其他部分...)? –

回答

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 
相關問題