2017-12-15 33 views
0

私は、私はこのようkivyに表示するファイルリストのパスを持っている:ListViewでファイルリストを表示する方法は? - PythonのKivy

excel_file.xlsx 

D.xlsx 

U.xlsx 

another_route.xlsx 

test.txt 

G.xlsx 

私はアイテムのリストとしてkivyでそれらを表示するために同じアルゴリズムを実装しています、I

G 

. 

x 

l 

s 

x 

私は正確に何が間違っているのか知りたいです。

class Routes_List_Screen(Screen): 
    path = "/home/pi/Documents/myRoutes" 
    dirs = os.listdir(path) 
    for file in dirs: 
     my_data = ListProperty(file) 
     print(file) # this is just to know what exactly is printing file variable 

KVファイル:

<Routes_List_Screen>: 
    canvas: 
     Color: 
      rgb: [.30, .30, .30] 
     Rectangle: 
      pos: self.pos 
      size: self.size 
    BoxLayout: 
     orientation: 'vertical' 
     ListView: 
      size_hint_y: .8 
      adapter: 
       ListAdapter(data=root.my_data, 
       selection_mode='single', 
       allow_empty_selection=False, 
       cls=ListItemButton) 
     Button: 
      text: 'Load' 

マイ出力:あなたはListPropertyに直接リストを渡す必要があります What I've got from kivy with the current code

答えて

1

class Routes_List_Screen(Screen): 
    path = "/home/pi/Documents/myRoutes" 
    dirs = os.listdir(path) 
    my_data = ListProperty(dirs) 

私はあなたに私のコードをお見せしましょう出力:

enter image description here

説明:

コード:

another_route.xlsx 
excel_file.xlsx 
G.xlsx 
U.xlsx 
test.xlsx 
D.xlsx 

最後に格納された値:あなたはすべての瞬間に変数my_dataを更新する前のコードで

for file in dirs: 
    my_data = ListProperty(file) 
    print(file) # this is just to know what exactly is printing file variable 

文字列はD.xlsx、文字列は繰り返し可能なので、文字列に分割します。

+0

私はテストしました。あなたのお返事ありがとうございます! – fabianpi

関連する問題