2016-10-01 10 views
0

私はこの問題を解決するためにオンラインでさまざまな例を見ようとしていましたが、まだ分かりません。私はポップアップクラスを呼び出すアプリケーションを持っています。ポップアップには入力フィールドがあり、入力フィールドのテキストを操作します。操作されたデータはポップアップクラス内の変数に格納されます。親ウィジェットは、このウィジェットから取得したデータにどのようにアクセスできますか。次に、コードの簡単な例を示します。Kivy Popoupからのデータへのアクセス

KV

<ScreenManagement>: 
ScreenManager: 
    id: manager 
    size_hint_y: 93 

    Screen: 
     name: "Case_info_screen" 
     id: sc1 

     FloatLayout: 
      BoxLayout: 

       orientation: 'vertical' 


       BoxLayout: 
        size_hint_y: 10 
        canvas.before: 
         Color: 
          rgb: 0.17, 0.17, 0.17 # your color here 
         Rectangle: 
          pos: self.pos 
          size: self.size 

        Label: 
         text_size: self.size 
         font_size: 20 
         valign: 'middle' 
         height: "75dp" 
         size_hint_y: None 
         color: 1,1,1,1 

         size_hint_x: 75 
         text: " Case Info" 
        RelativeLayout: 
         size_hint_x: 25 

         Button: 
          text_size: self.size 
          halign: 'center' 
          valign: 'middle' 
          size_hint: 0.70, 0.6 
          pos_hint: {'center_x': 0.5, 'center_y': 0.5} 
          text: 'Automatic Filler' 
          on_press: root.formfiller() 

       BoxLayout: 

        size_hint_y: 5 
        spacing: 35 
        LabelCases: 
         text: ' Name: ' 
         width: '125dp' 
         size_hint_x: None 


        TextInput: 
         id: first_name_input 
         width: '300dp' 
         height: '40dp' 
         size_hint_x: None 
         font_size: 18 


         hint_text: 'First Name' 

        TextInput: 
         id: last_name_input 
         width: '300dp' 
         height: '40dp' 
         size_hint_x: None 
         font_size: 18 
         hint_text: 'Last Name' 

<Formfillerpop>: 
    title: 'Automatic Filler' 
    size_hint: None, None 
    size: 600, 600 
    BoxLayout: 
     orientation: 'vertical' 
     Label: 
      size_hint_y: 20 
      text: 'Please Paste your text' 
      markup: True 
     TextInput: 
      id: sentence 
      size_hint_y: 65 
     BoxLayout: 
      size_hint_y: 10 
      orientation: 'horizontal' 
      Button: 
       text: 'Analyze' 
       on_press: root.on_analyze(sentence.text) 
      Button: 
       text: 'Close' 
       on_press: root.closepop() 

のPython:

class Formfillerpop(Popup): 
    selection = StringProperty 
    id = ObjectProperty 
    def on_analyze(self, selection): 
     analyze = TextExtractor(selection) 

     names = analyze.name() 




    def closepop(self): 
     self.dismiss() 


class ScreenManagement(FloatLayout): 
    def formfiller(self, *args): 
     Formfillerpop().open() 




class IOApp(App): 
    def build(self): 
     return ScreenManagement() 


if __name__ == '__main__': 
    IOApp().run() 

最終的に私は、ポップアップ内の名前からTXTを取った後、分析したデータをメインアプリで姓と名を自動入力したいです これが基本的な場合は申し訳ありません。私はかなり新しいKivyです。

答えて

0

ポップアップコンテンツには、contentプロパティを使用してアクセスできます。あなたはtextの読み取りの性質を読むためにそれを使用することができますTextInput。たとえば、このコードはこのプロパティをローカルpopup_text StringPropertyにバインドします。つまり、ポップアップテキスト入力の変更が反映されます。

from kivy.uix.popup import Popup 
from kivy.uix.button import Button 
from kivy.uix.boxlayout import BoxLayout 
from kivy.app import App 
from kivy.lang import Builder 
from kivy.properties import StringProperty 

Builder.load_string(''' 
<CustomPopup>: 
    size_hint: .5, .5 
    auto_dismiss: False 
    title: 'Hello world' 
    BoxLayout: 
     text_input: text_input 
     orientation: 'vertical' 
     TextInput: 
      id: text_input 
     Button: 
      text: 'dismiss'  
      on_press: root.dismiss() 
''') 

class CustomPopup(Popup): 
    pass 

class TestApp(App): 
    popup_text = StringProperty() 

    def build(self): 
     l = BoxLayout() 
     l.add_widget(Button(
      text='show_popup', on_press=self.show_popup 
     )) 
     l.add_widget(Button(
      text='print popup text', on_press=self.print_popup_text 
     )) 
     return l  

    def show_popup(self, *args): 
     p = CustomPopup() 
     p.content.text_input.bind(text=self.setter('popup_text')) 
     p.open() 

    def print_popup_text(self, *args): 
     print(self.popup_text) 

if __name__ == '__main__': 
    TestApp().run() 
関連する問題