python 3.x - Kivy Scrollable Label and text file, label wont update -


hy, problem current code, @ point preety nothing text editor, when ever try make scrollable label in kv language , call on main screen @ push of button, no error, theres nothing there. should mention text taken stored file, , version works regular label. code, know bit long preety easy understand stay me. sort of input apreciated , thank taking time.

#kivy.require("1.8.0") kivy.app import app kivy.lang import builder kivy.uix.screenmanager import screenmanager, screen, fadetransition kivy.uix.widget import widget kivy.uix.scatter import scatter kivy.uix.label import label kivy.uix.scrollview import scrollview kivy.uix.floatlayout import floatlayout kivy.uix.textinput import textinput kivy.properties import stringproperty kivy.uix.boxlayout import boxlayout kivy.graphics import line kivy.uix.gridlayout import gridlayout   kv = ''' #: import fadetransition kivy.uix.screenmanager.fadetransition  screenmanager:     transition: fadetransition()     mainscreen:     addscreen:     appendscreen:   <scattertextwidget>:     orientation: 'vertical'      textinput:         id: main_input         font_size: 14         size_hint_y: none         height: root.height - botones_layout.height         font_color: [0.1,0.3,0.9,1]         focus: true         foreground_color: [0.2,0.5,0.9,1]         cursor_color: [0,0,1,1]      boxlayout:         id: botones_layout         orientation: 'horizontal'         height: 30         button:             id: home_button             text: "back home"                     button:             id: save_button             text: "save file"             on_press: root.savetofile("archive.txt", main_input.text)   <appendtextwidget>:     orientation: 'vertical'      textinput:         text: root.text         id: main_input         font_size: 14         size_hint_y: none         height: root.height - botones_layout.height         font_color: [0.1,0.3,0.9,1]         focus: true         foreground_color: [0.2,0.5,0.9,1]         cursor_color: [0,0,1,1]      boxlayout:         id: botones_layout         orientation: 'horizontal'         height: 30         button:             id: home_button             text: "back home"             on_release: app.root.current = "main"         button:             id: save_button             text: "save"             on_press: root.append(main_input.text)  #this not work <--- <--- <---  <scrollablelabel>:     label:         text: root.text         font_size: 15         text_size: self.width, none         color: [0,255,0,1]         padding_x: 20         size_hint_y: none         pos_hint: {"left":1, "top":1}         height: self.texture_size[1]   <mainscreen>:     name: "main"     floatlayout:          # work           label:             text: root.text             font_size: 15             text_size: self.width, none             color: [0,255,0,1]             padding_x: 20             size_hint_y: none             pos_hint: {"left":1, "top":1}             height: self.texture_size[1]              actionbar:         pos_hint: {'top':1}         actionview:             use_separator: true             actionprevious:                 title: "text"                 with_previous: false             actionoverflow:             actionbutton:                 text: "new"                 on_release: app.root.current = "add"             actionbutton:                 text: "update"                 on_press: root.clicked()             actionbutton:                 text: "add"                 on_release: app.root.current = "append"   <addscreen>:     name: "add"     floatlayout:          scattertextwidget  <appendscreen>:     name: "append"     floatlayout:         appendtextwidget          '''   class scattertextwidget(boxlayout):     def savetofile(self,name,text):         f = open(name, "w")         f.write("\n\n\n" + "    " + ">>>" + text + "test"*500)         f.close()  class appendtextwidget(boxlayout):     text = stringproperty("")     def append(self,text):         open("archive.txt", "a") f:             f.write("\n" + "    " + ">>>" + text)             f.close()     class scrollablelabel(scrollview):      text = stringproperty('')      pass   class mainscreen(screen):     text = stringproperty("")      def clicked(self):         open("archive.txt", "r") f:             contents = f.read()             self.text = contents     pass  class addscreen(screen):     pass  class appendscreen(screen):     pass      class myapp(app):      def build(self):         return builder.load_string(kv)    if __name__ == '__main__':     myapp().run() 

why works:

your text in mainscreen updated file, passed label , text loaded. scrollablelabel.text stays unchanged.

why doesn't work expect:

there's no communication between classes, therefore text changed actual self.text = mainscreen.text

how make work:

either use on global range, i.e. variable in app class, a = app.get_running_app() , access variable through a.<variable> or use __init__ initialize scrollablelabel inside mainscreen , pass text

so it's duplicate of this , 1 duplicate of older unsimplified question.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -