Как я могу просто использовать сохраненное значение - PullRequest
0 голосов
/ 29 апреля 2019

У меня есть программа, в которую я хочу добавить советы.При первом открытии программы отображаются подсказки, а при нажатии правой кнопки подсказки больше не исчезают.И когда он открывает программу во второй раз, мне нужны подсказки, которые до сих пор не отображаются, пока он не нажмет другую кнопку, которая покажет подсказки.

Я могу сделать это через файлы .txt и, возможно, через базу данных firebase, но есть ли ещепросто способ для меня это сделать?Потому что я не хочу другой файл .txt в моей программе.

Основной файл .py:

from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.properties import NumericProperty
from kivy.uix.button import ButtonBehavior
from kivy.uix.image import Image
import slovar

...classes...

class OpenScreen(Screen):
    ....

    def help_off(self):
        self.ids.tp_s.text = '\n'
        self.ids.tp_s1.text = '\n'
        self.ids.tp_s2.text = '\n'
        self.ids.tp_s3.text = '\n'
        f3 = open('numbers.txt', 'w')
        f3.write(self.ids.tp_s.text)
        f3.write(self.ids.tp_s1.text)
        f3.write(self.ids.tp_s2.text)
        f3.write(self.ids.tp_s3.text)
        f3.close()

    def help_on(self):
        self.ids.tp_s.text = ('777'+'999999')
        self.ids.tp_s1.text = '8'
        self.ids.tp_s2.text = '99'
        self.ids.tp_s3.text = '6'
        f3 = open('numbers.txt', 'w')
        f3.write(self.ids.tp_s.text)
        f3.write(self.ids.tp_s1.text)
        f3.write(self.ids.tp_s2.text)
        f3.write(self.ids.tp_s3.text)
        f3.close()


class SettingsScreen(Screen):
    pass


GUI = Builder.load_file('game.kv')
class GameApp(App):
    def build(self):
        return GUI

    def change_screen(self, screen_name):
        screen_manager = self.root.ids['screen_manager']                
        screen_manager.current = screen_name

    def on_start(self):
        count = 0
        f1 = open('numbers.txt', 'r')
        for i in f1:
            count += 1
            if count == 1:
                self.root.ids['open_screen'].ids['tp_s'].text = i
                print(i)
            elif count == 2:
                self.root.ids['open_screen'].ids['tp_s1'].text = i
                print(i)
            elif count == 3:
                self.root.ids['open_screen'].ids['tp_s2'].text = i
                print(i)
            elif count == 4:
                self.root.ids['open_screen'].ids['tp_s3'].text = i
                print(i)
        f1.close()

GameApp().run()

Экран настроек .kv файл:

<SettingsScreen>:
    FloatLayout:
        canvas:
            Rectangle:
                size: self.size
                pos: self.pos
                source: 'bg.png'
        Label:
            size_hint: .7, .1
            pos_hint: {'x': .08, 'y':.78}
            text: 'HELP:'
            font_size: self.width//8
            text_size: self.size
            valign: 'middle'
            halign: 'left'
        Button:
            size_hint: .1, .1
            pos_hint: {'x': .7, 'y': .78}
            on_release:
                app.root.ids.open_screen.help_off()
        Button:
            size_hint: .1, .1
            pos_hint: {'x': .85, 'y': .78}
            on_release:
                app.root.ids.open_screen.help_on()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...