В настоящее время я храню весь текст, введенный пользователем в файл.когда я запускаю этот код, кнопки screenfive text root.a и root.b являются предыдущими записями, но не вводят текущий ввод текста.
означает, что при первом выполнении я ввел firstname1 и lastname1 на экране four.in на кнопке экрана Five, которую я вижу с помощью (с), потому что это первый раз, когда файлы создаются, поэтому нет текста вих.
во втором исполнении я набираю fistname2 и lastname2 на экране четыре, но когда я перехожу на экран пять, он отображает «firstname1 with firstname1» в тексте кнопки, но я ожидаю «firstname2 with lastname2», что и былоя ввел во время текущего выполнения это код Python:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.core.window import Window
from kivy.uix.textinput import TextInput
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.scatter import Scatter
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.config import Config
from kivy.base import runTouchApp
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty, NumericProperty, StringProperty
root = FloatLayout()
class ScreenManagement(ScreenManager):
pass
class A(Screen):
pass
class B(Screen):
pass
class C(Screen):
pass
class ScreenFour(Screen):
group_text_input = ObjectProperty()
disability_text_input = ObjectProperty()
grouptextinput = StringProperty('')
disabilitytextinput = StringProperty('')
global grouptextinput, disabilitytextinput
def submit_textinput(self):
self.grouptextinput = self.group_text_input.text
print("group of people: {}".format(self.grouptextinput))
self.save()
self.disabilitytextinput = self.disability_text_input.text
print("with following disability: {}".format(self.disabilitytextinput))
self.save2()
def save(self):
with open("grouptextinput.txt", "w") as fobj:
fobj.write(str(self.grouptextinput))
def save2(self):
with open("disabilitytextinput.txt", "w") as fobj:
fobj.write(str(self.disabilitytextinput))
pass
class Help(Screen):
pass
class ScreenFive(Screen):
box = ScreenFour()
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
print 'file is opened'
a = myfile.readline(14)
print a
myfile = open('disabilitytextinput.txt','r')
print 'file is opened'
b = myfile.readline(14)
print b
## a = box.grouptextinput
## b = box.grouptextinput
pass
class ScreenSix(Screen):
pass
class One(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Two(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Three(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Four(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Five(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Six(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Seven(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Eight(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
class Nine(Screen):
a = StringProperty()
b = StringProperty()
myfile = open('grouptextinput.txt','r')
a = myfile.readline(14)
myfile = open('disabilitytextinput.txt','r')
b = myfile.readline(14)
pass
presentation = Builder.load_file("main.kv")
class MainApp(App):
def build(self):
return presentation
if __name__ == "__main__":
MainApp().run()
и это код KIVY:
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
transition: FadeTransition()
A:
B:
C:
ScreenFour:
Help:
ScreenFive:
ScreenSix:
One:
Two:
Three:
Four:
Five:
Six:
Seven:
Eight:
Nine:
<A>:
name: "llll"
Button:
on_release: app.root.current = "iiii"
Image:
source: '************'
center_x: self.parent.center_x
center_y: self.parent.center_y
<Intentions>:
name: "iiii"
Image:
source: '***********'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Next'
id: button
font_size: 40
size_hint: None, None
on_release: app.root.current = "pppp"
pos: 590,50
size: 200, 60
<Picot>:
name: "pppp"
Image:
source: '****************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Next'
id: button
font_size: 40
size_hint: None, None
on_release: app.root.current = "screenfour"
pos: 590,50
size: 200, 60
<ScreenFour>
name: "screenfour"
group_text_input: group
disability_text_input: disability
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: '***************'
Label:
text: "**********"
font_size: '47sp'
pos: 0, 100
color: 0,0,0,1
bold: True
TextInput:
id: group
multiline: False
size_hint_x: .3
size_hint_y: .1
hint_text: '************'
pos: 90, 220
font_size: '29sp'
Label:
text:"********"
font_size: '40sp'
pos: 0, -50
color: 0,0,0,1
bold: True
TextInput:
id: disability
multiline: True
size_hint_x: .3
size_hint_y: .1
hint_text: '*********'
pos: 465, 220
font_size: '29sp'
Button:
text: 'Next'
id: button
font_size: 40
size_hint: None, None
on_release: app.root.current = "screenfive"
on_release: root.submit_textinput()
pos: 590,50
size: 200, 60
Button:
text: 'Help!'
id: button
font_size: 30
size_hint: None, None
on_release: app.root.current = "help"
pos: 50,50
size: 100, 60
<Help>
name: "help"
Image:
source: '******************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: '*********'
id: button
font_size: 40
size_hint: None, None
on_release: app.root.current = "screenfour"
pos: 590,50
size: 200, 60
<ScreenFive>
name:"screenfive"
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: '***************'
Label:
text: '********'
font_size: '60sp'
pos: 0, 150
color: 0,0,0,1
bold: True
Label:
text: '**********'
font_size: '53sp'
pos: 0, 75
color: 0,0,0,1
bold: True
Label:
text: '*******'
font_size: '60sp'
pos: 0, 0
color: 0,0,0,1
bold: True
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size: 760, 100
size_hint: None, None
pos: 20,150
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
Button:
text: 'Continue'
id: button
font_size: 40
size: 200, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 590,50
<ScreenSix>
name: "menu"
canvas:
Color:
rgb: .5, .5, .5
Rectangle:
size: self.size
GridLayout:
cols: 3
spacing: 20
padding: [20,50]
Label:
text: ''
Label:
text: '************'
font_size: '19sp'
Label:
text: ''
Button:
text: '********'
#on_press: root.manager.current = 'settings'
on_release: app.root.current = "one"
Button:
text: '*******'
on_release: app.root.current = "two"
Button:
text: '*****'
on_release: app.root.current = "three"
Button:
text: '********'
on_release: app.root.current = "four"
Button:
text: '********'
on_release: app.root.current = "five"
Button:
text: '********'
on_release: app.root.current = "six"
Button:
text: '*******'
on_release: app.root.current = "seven"
Button:
text: '*********'
on_release: app.root.current = "eight"
Button:
text: '***********'
on_release: app.root.current = "nine"
<One>
name: "one"
Image:
source: '********'
y: self.parent.y
x: self.parent.x
allow_stretch: True
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
allow_stretch: True
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Two>
name: "two"
Image:
source: '*******'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Three>
name: "three"
Image:
source: '***********'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Four>
name: "four"
Image:
source: '*************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Five>
name: "five"
Image:
source: '********************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Six>
name: "six"
Image:
source: '************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Seven>
name: "seven"
Image:
source: '*******************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Eight>
name: "eight"
Image:
source: '********************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
<Nine>
name: "nine"
Image:
source: '***************'
y: self.parent.y
x: self.parent.x
allow_stretch: True
size: 800, 750
Button:
text: 'Back To Menu'
id: button
font_size: 40
size: 300, 60
size_hint: None, None
on_release: app.root.current = "menu"
pos: 100,13
Button:
text: root.a + ' WITH ' + root.b
font_size: 40
text_size: self.width, None
size_hint: None, None
halign: 'center'
background_color: (0, 0, 0, 1)
color: 1, 1, 1, 1
pos: 0,520
size: 800, 80
Я новичок в Python и KIVY и оба, и это последнийвещь, которая удерживает меня от создания моего первого приложения. Я был бы очень благодарен, если бы кто-то мог помочь мне.