前提・実現したいこと
pythonのkivyでToDoアプリ的なものを作ろうとしています。そこで、RecycleViewを使って登録したToDoを表示させようとしているのですが写真のように二重になって表示されてしまいました。どうしたらいいかわからず躓いてしまいました。
どうすればいいかアドバイスもらえるとありがたいです。
参考にしたサイト1
参考にしたサイト2
該当のソースコード
.pyファイル
from kivy.config import Config Config.set('graphics', 'resizable', False) Config.set('graphics', 'width', '400') Config.set('graphics', 'height', '500') from kivy.app import App from kivy.lang import Builder from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition import sqlite3 from kivy.uix.scrollview import ScrollView from kivy.properties import ListProperty from kivy.uix.gridlayout import GridLayout from kivy.uix.popup import Popup Builder.load_file('todo.kv') class CreateScreen(Screen): def create(self): if not self.ids.year_0.text.isdecimal() or not self.ids.month_0.text.isdecimal() or not self.ids.month_0.text.isdecimal() or not len(self.ids.plan_0.text) >= 1: popup = Popup(title='Error', content=Label(text='Please fill in the blanks \n or\nPlease check the contents'), size_hint=(0.5, 0.3), pos_hint={"x":0.25, "top": 0.65}) popup.open() else: year = self.ids.year_0.text month = self.ids.month_0.text day = self.ids.day_0.text plan = self.ids.plan_0.text db = sqlite3.connect('schedule.db') cursor = db.cursor() cursor.execute("CREATE TABLE IF NOT EXISTS schedule(date, plan)"); aa = "{}/{}/{}".format(year, month, day) data = (aa, plan) cursor.execute("INSERT INTO schedule VALUES(?, ?)", data) db.commit() self.ids.year_0.text = '' self.ids.month_0.text = '' self.ids.day_0.text = '' self.ids.plan_0.text = '' class CheckScreen(Screen): rows = ListProperty([("date", "plan")]) def update(self): db = sqlite3.connect('schedule.db') cursor = db.cursor() cursor.execute("SELECT COUNT(*) FROM sqlite_master WHERE TYPE='table' AND name='schedule'") if cursor.fetchone()[0] == 0: popup = Popup(title='Error', content=Label(text='Please fill in the blanks \n or\nPlease check the contents'), size_hint=(0.5, 0.3), pos_hint={"x":0.25, "top": 0.65}) popup.open() else: cursor.execute("SELECT * FROM Schedule") rows = cursor.fetchall() self.rv.data = [] for date, plan in rows: self.rv.data.append({'data': (date, plan)}) sm = ScreenManager(transition=FadeTransition()) sm.add_widget(CreateScreen(name='create')) sm.add_widget(CheckScreen(name="check")) sm.current = 'check' class ToDoApp(App): title = 'ToDo Application' def build(self): return sm if __name__ == '__main__': ToDoApp().run()
.kvファイル
<CreateScreen> FloatLayout: BoxLayout: size_hint: 1, 0.1 pos_hint: {"x":0, "top":1} Button: text: "Create" canvas.before: Color: rgba: 0, 1, 1, 1 Rectangle: pos: self.pos size: self.size on_press: root.manager.current = 'create' background_nomal: '' background_color: 0, 1, 1, 1 Button: canvas.before: Color: rgba: 0, 1, 1, 1 Rectangle: pos: self.pos size: self.size on_press: root.manager.current = 'check' text: "Check" BoxLayout: size_hint: 0.8, 0.05 pos_hint: {"x":0.1, "top":0.9} Label: text:'Year' canvas.before: Color: rgba: 0, 1, 0, 0.5 Rectangle: pos: self.pos size: self.size TextInput: id: year_0 multiline:False BoxLayout: size_hint: 0.8, 0.05 pos_hint: {"x":0.1, "top":0.8} Label: text:'Month' canvas.before: Color: rgba: 0, 1, 0, 0.5 Rectangle: pos: self.pos size: self.size TextInput: id: month_0 multiline:False BoxLayout: size_hint: 0.8, 0.05 pos_hint: {"x":0.1, "top": 0.7} Label: text: 'Day' canvas.before: Color: rgba: 0, 1, 0, 0.5 Rectangle: pos: self.pos size: self.size TextInput: id: day_0 multiline: False BoxLayout: orientation:'vertical' size_hint: 0.8, 0.5 pos_hint: {"x": 0.1, "top": 0.6} Label: size_hint: 1, 0.05 text: 'Plan' canvas.before: Color: rgba: 0, 1, 0, 0.5 Rectangle: pos: self.pos size: self.size TextInput: id: plan_0 size_hint: 1, 0.45 BoxLayout: size_hint: 0.6, 0.05 pos_hint: {"x": 0.2, "top": 0.06} Button: text: 'Create' on_press: root.create() <CheckScreen> rv: rv FloatLayout: BoxLayout: size_hint: 1, 0.1 pos_hint: {"top":1} Button: text: "Create" canvas.before: Color: rgba: 0, 1, 1, 1 Rectangle: pos: self.pos size: self.size on_press: root.manager.current = 'create' Button: canvas.before: Color: rgba: 0, 1, 1, 1 Rectangle: pos: self.pos size: self.size on_press: root.manager.current = 'check' text: "Check" background_nomal: '' background_color: 0, 1, 1, 1 BoxLayout: size_hint: 1, 0.1 pos_hint: {"x": 0, "top":0.9} Label: text: 'Schedule List' canvas.before: Color: rgba: 1, 1, 1, 0.7 Rectangle: pos: self.pos size: self.size BoxLayout: size_hint: 1, 0.05 pos_hint: {"x":0, "top":0.8} Label: text: 'Date' size_hint: 0.3, 1 pos_hint: {"x":0, "top":1} Label: text: 'Plan' size_hint: 0.8, 1 pos_hint: {"x": 0.3, "top": 1} BoxLayout: size_hint: 0.6, 0.05 pos_hint: {"x": 0.2, "y":0.01} Button: text: 'Reload' on_press: root.update() RecycleView: id: rv size_hint_y: 0.6 pos_hint: {"x":0, "top": 0.75} scroll_type: ['bars', 'content'] scroll_wheel_distance: sp(60) bar_width: sp(10) viewclass: 'ROW' RecycleBoxLayout: default_size: None, sp(35) default_size_hint: 1, None size_hint_y: None orientation: 'vertical' height: self.minimum_height spacing: dp(8) <ROW@BoxLayout>: data: ('','') Label: text: root.data[0] Label: text: root.data[1] <Widget>: canvas.after: Color: rgba: 1, 1, 1, 1 Line: rectangle: self.x+1,self.y+1,self.width-1,self.height-1 dash_offset: 5 dash_length: 3
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/13 03:51