2016-10-01 2 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() 

파이썬 :

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을 한 후 분석 된 데이터와 주요 응용 프로그램의 이름과 성을 자동으로 채운합니다 이것이 기본이면 죄송합니다. 나는 키비에게 상당히 새로운 사람이다.

답변

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() 
관련 문제