2016-09-16 16 views
0

最初に私はkivyを初めて使っています。 myAppはkivy-example/demo/kivycatlogに基づいており、PopupContainer.kvを変更していましたが、私のコードは機能しません。Kivy POPUPとボタンのテキスト

PopupContainer.kv

BoxLayout: 
    id: bl 
    orientation: "vertical" 
    popup: popup.__self__ 
    canvas: 
     Color: 
      rgba: .18, .18, .18, .91 
     Rectangle: 
      size: self.size 
      pos: self.pos 
    Button: 
     id: showPopup1 
     text: 'press to show popup' 
     on_release: root.popup.open() 
    Button: 
     id: showPopup2 
     text: 'press to show popup' 
     on_release: root.popup.open() 

Popup: 
    id: popup 
    on_parent: if self.parent == bl: bl.remove_widget(self) 
    title: "An example popup" 
    BoxLayout: 
     orientation: 'vertical' 
     BoxLayout: 
      orientation: 'vertical' 
      Button: 
       id: accept 
       text: "yes" 
       on_release: status.text = self.text 
      Button: 
       id: cancel 
       text: "no" 
       on_release: status.text = self.text 
      Label: 
       id: status 
       text: "yes or no?" 
     Button: 
      text: "press to dismiss" 
      on_release: popup.dismiss() 

私はshowPopupのテキストに "はい" または "いいえ" をクリックしたときtext(showPopup)を変更したいです。

答えて

0

コードからShowPopupのボタンのテキストを取得できます。私はあなたのコードにpopups_textという名前の変数を宣言し、.kvファイルにはroot.popups_textを使ってアクセスしようとしています。ボタンを押すたびにこのテキストを変更するメソッドをコード内に作成します。

+0

um ....私はまだそれを試しています コード内でリレーショナル変数を作成するには? –

+0

問題がどこにあるのかわかりません – Juggernaut

関連する問題