質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Kivy

Kivyは、Pythonを用いたNUI開発のためのオープンソースフレームワーク。マルチタッチなど多くの入力に対応したNUIアプリなどを開発することができます。多くの環境で動作するクロスプラットフォームです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

3296閲覧

python kivyのrecycleviewについて

inori10

総合スコア17

Kivy

Kivyは、Pythonを用いたNUI開発のためのオープンソースフレームワーク。マルチタッチなど多くの入力に対応したNUIアプリなどを開発することができます。多くの環境で動作するクロスプラットフォームです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/10/13 01:51

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

todo.kvが二度読み込まれているのが原因ですね。

一つはBuilder.load_file('todo.kv')
もう一つはKivyがAppclassの名前から自動で読みこんでます。

なので解決策は

  1. todo.kvの名前を変える
  2. Builder.load_file('todo.kv')を消した上でsmの作成を全てbuild()method内で行う

のどちらかです。

投稿2019/10/13 03:42

編集2019/10/13 03:53
gottadiveintopy

総合スコア736

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

inori10

2019/10/13 03:51

できました! ありがとうござます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問