在kv中引用csv文件

时间:2018-05-15 07:19:06

标签: python csv kivy

我试图在csv文件中写一个信息并在按下按钮后获取它(以便检查它是否写得正确)但是,我从PutOnShelfScreen1类获取信息(True或False取决于小部件的位置)。我有点陷入我试图弄错我错的地方。 这是我的代码。

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty

import csv

Builder.load_string('''
<Sample@Image>:
    size: self.size
    allow_stretch: False
    keep_ratio: False
    do_rotation: False

<PutOnShelfScreen1>:
    canvas:
        Rectangle:
            source: 'BackForGame113.png'
            size: self.size
            pos: self.pos
    BoxLayout:
        orientation: 'horizontal'
        spacing: 30
        padding: [10, 150, 10, 10]
        Button:
            id: Tools
            background_color: [63, 191, 63, 0.3]
            text: ''
        Button:
            id: Transportation
            background_color: [63, 191, 63, 0.3]
            text: ''
        Button:
            id: Furniture
            background_color: [63, 191, 63, 0.3]
            text: ''
    FloatLayout:
        Button:
            id: Next
            pos_hint: {'x': 0.8, 'y': 0.9}
            size_hint: .2, .1
            background_color: [63, 191, 63, 0.3]
            text: '>'
            on_press: root.DataBase(database)

    StencilView:
        id: armchair
        ScatterPlane:
            pos: 500, 500
            size: my_image2.size
            Image:
                id: my_image2
                source: 'path\\image.png'
                on_touch_up: root.Count(Furniture, Tools, Transportation, armchair)

''')

data = ['Bla', '6']

class PutOnShelfScreen1(Screen):

    def Count(self, Transportation, Furniture, Tools, armchair):
        Transportation = self.ids.Transportation
        Furniture = self.ids.Furniture
        Tools = self.ids.Tools
        armchair = self.ids.my_image2.parent

        i = 0
        if (armchair.collide_widget(Furniture)) is True:
            i += 1

        print(armchair.collide_widget(Furniture))


class DataBase():
    database = ObjectProperty

    def __init__(self, i, **kwargs):
        super().__init__(**kwargs)
        self.data = data.append(i)
        self.database = 'results.csv'

    def Table(self):

        with open('результаты.csv', 'w') as database:
            wr = csv.writer(database, delimiter=' ', quoting=csv.QUOTE_MINIMAL)
            wr.writerow(['Column', 'Column', 'Result'])
            wr.writerow(data)

        with open('results.csv', 'r') as database:
            reader = csv.reader(database)
            for row in reader:
                print(row)

sm = ScreenManager()
sm.add_widget(PutOnShelfScreen1(name='class'))

class SampleApp(App):
    def build(self):
        return (sm)

if __name__ == "__main__":
    SampleApp().run()

0 个答案:

没有答案