###前提・実現したいこと
kivyを使用してGUIの作成をしています。
アプリ起動後、ログインページを経由した後、テーブルを作成・表示したいのですが難航しています。
###該当のソースコード
python
1from kivy.config import Config 2Config.set('graphics', 'width', '300') 3Config.set('graphics', 'height', '150') 4 5from random import sample 6from string import ascii_lowercase 7 8from kivy.app import App 9from kivy.lang import Builder 10from kivy.uix.widget import Widget 11from kivy.core.window import Window 12from kivy.uix.recycleview import RecycleView 13from kivy.uix.screenmanager import ScreenManager, Screen 14from kivy.properties import StringProperty, ObjectProperty 15 16#Builder.load_file("./GUI.kv") 17Builder.load_string(""" 18<LoginScreen>: 19 BoxLayout: 20 orientation: 'vertical' 21 pos: root.pos 22 size: root.size 23 BoxLayout: 24 Label: 25 text: 'User ID:' 26 BoxLayout: 27 orientation: 'vertical' 28 Label: 29 TextInput: 30 id: ti 31 multiline: False 32 Label: 33 BoxLayout: 34 size_hint: 1.0, 0.5 35 Button: 36 text: 'Login' 37 font_size: 16 38 on_press: root.Login(ti) 39 Button: 40 text: 'Cancel' 41 font_size: 16 42 on_press: root.Cancel(ti) 43 44<ListScreen>: 45 rv: rv 46 BoxLayout: 47 orientation: 'vertical' 48 BoxLayout: 49 canvas: 50 Color: 51 rgba: 0.3, 0.3, 0.3, 1 52 Rectangle: 53 size: self.size 54 pos: self.pos 55 orientation: 'vertical' 56 GridLayout: 57 cols: 3 58 rows: 2 59 size_hint_y: None 60 height: dp(108) 61 padding: dp(8) 62 spacing: dp(16) 63 Button: 64 text: 'Populate list' 65 on_press: root.populate() 66 Button: 67 text: 'Sort list' 68 on_press: root.sort() 69 Button: 70 text: 'Clear list' 71 on_press: root.clear() 72 BoxLayout: 73 spacing: dp(8) 74 Button: 75 text: 'Insert new item' 76 on_press: root.insert(new_item_input.text) 77 TextInput: 78 id: new_item_input 79 size_hint_x: 0.6 80 hint_text: 'value' 81 padding: dp(10), dp(10), 0, 0 82 BoxLayout: 83 spacing: dp(8) 84 Button: 85 text: 'Update first item' 86 on_press: root.update(update_item_input.text) 87 TextInput: 88 id: update_item_input 89 size_hint_x: 0.6 90 hint_text: 'new value' 91 padding: dp(10), dp(10), 0, 0 92 Button: 93 text: 'Remove first item' 94 on_press: root.remove() 95 RecycleView: 96 id: rv 97 scroll_type: ['bars', 'content'] 98 scroll_wheel_distance: dp(114) 99 bar_width: dp(10) 100 RecycleBoxLayout: 101 #viewclass: 'Row' 102 default_size: None, dp(56) 103 default_size_hint: 1, None 104 size_hint_y: None 105 height: self.minimum_height 106 orientation: 'vertical' 107 spacing: dp(2) 108 BoxLayout: 109 size_hint: 1.0, 0.1 110 Label: #Dummy 111 Button: 112 text: "Load" 113 on_release: root.Load() 114 Label: #Dummy 115""") 116 117class ListScreen(Screen): 118 119 def populate(self): 120 self.rv.data = [{'value': ''.join(sample(ascii_lowercase, 6))} 121 for x in range(50)] 122 print(self.rv.data) 123 124 def sort(self): 125 self.rv.data = sorted(self.rv.data, key=lambda x: x['value']) 126 127 def clear(self): 128 self.rv.data = [] 129 130 def insert(self, value): 131 self.rv.data.insert(0, {'value': value or 'default value'}) 132 133 def update(self, value): 134 if self.rv.data: 135 self.rv.data[0]['value'] = value or 'default new value' 136 self.rv.refresh_from_data() 137 138 def remove(self): 139 if self.rv.data: 140 self.rv.data.pop(0) 141 142 143class LoginScreen(Screen): 144 def Login(self, ti): 145 app = App.get_running_app() 146 147 app.user = ti.text 148 149 if ti.text.isdigit(): 150 print("Login:[%s]" % ti.text) 151 Window.size = (800, 600) 152 sm.current = "List" 153 sm.remove_widget(self) 154 else: 155 print("Wrong ID!") 156 ti.text = "" 157 158 def Cancel(self, ti): 159 print("Cancel") 160 ti.text = "" 161 162 163class TestApp(App): 164 user = StringProperty(None) 165 166 def build(self): 167 sm = ScreenManager() 168 sm.add_widget(LoginScreen(name="LogIn")) 169 sm.add_widget(ListScreen(name="List")) 170 return sm 171 172 173if __name__ == '__main__': 174 TestApp().run() 175
###試したこと
現状、ログイン後にボタンを押すことでスクロールバーを表示するとこまでできています(といっても、exampleを埋め込んだだけなのですが。。。)
ログイン後に[Populate list]ボタンを押すことでexample同様ランダムで生成された文字列のリストを表示して欲しいのですが、何卒ご教示お願いいたします。
###補足情報(言語/FW/ツール等のバージョンなど)
python 3.4
kivy 1.10
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。