2017-12-24 5 views
0

Pythonでアプリケーションを作成するのはかなり新しく、ほかのクラスの関数から他のクラスの関数への引数を渡す方法がわかりません。私が読んだことに基づいて、私はの初期設定をCustomPopupクラスで使うべきだと思いますが、それを動作させることができませんでした。他のクラスから別のクラスへ属性を取得するPython

のPython:

from kivy.app import App 
from kivy.lang import Builder 
from os import listdir 
from kivy.uix.screenmanager import Screen, ScreenManager 
from kivy.uix.popup import Popup 
import teradata 
import Global 

class CustomPopup(Popup): 
    txt_input = 'Text' 

udaExec = teradata.UdaExec() 

kv_path = './kv/' 
for kv in listdir(kv_path): 
    Builder.load_file(kv_path+kv) 

class LoginScreen(Screen): 

    def buttonClicked(self): 
     Global.u_name = self.ids.u_name.text 
     Global.p_word = self.ids.p_word.text 
     status = None 
     try: 
      with udaExec.connect("${dataSourceName}",username=self.ids.u_name.text,password=self.ids.p_word.text) as session: 
       try: 
        session 
       except teradata.DatabaseError as e: 
        status = e.code 
     except teradata.DatabaseError as e: 
      status = e.code 

     if status == 8017: 
      self.popuper('Hello') 
     elif status == None: 
      self.popuper('All Good') 
     elif status == 0: 
      self.popuper('Fill in username') 
     else: 
      self.popuper('Something else') 

    def popuper(self, txt_input): 
     popuper = CustomPopup() 
     popuper.open() 

class MainScreen(Screen): 
    pass 

class ScreenManagement(ScreenManager): 
    pass 

application = Builder.load_file("main.kv") 

class MainApp(App): 

    def build(self): 
     self.title = 'Push Notfication Tool' 
     return application 

if __name__ == "__main__": 
    MainApp().run() 

Kivyここ

は、この作品が、私はCustomPopupにpopuperからtxt_inputを取得しようとしていますが、それは働いて得ることができない私が何をしようとしています何の剥奪バージョンです:

<[email protected]>: 
    size_hint: (.5,.5) 
    auto_dismiss: False 
    title: "af" 
    BoxLayout: 
     orientation: 'vertical' 
     Label: 
      text: root.txt_input 
     Button: 
      text: "Close now" 
      on_press: root.dismiss() 

ありがとうございます!

* EDITでkivyファイルも追加されました。

+0

[、最小完全、かつ検証例]を提供してください(https://stackoverflow.com/help/ mcve) - あなたのコードは正しい字下げや構文がなければ意味をなさない - 要するに、atmは動作していない。 - '__init__'はf.eです。ここでcovored:https://stackoverflow.com/a/625097/7505395 –

+0

[Python \ _ \ _ init \ _ \ _の可能な複製と彼らは何をしていますか?](https://stackoverflow.com/questions/625083)/python-init-and-self-what-do-they-do) –

+0

こんにちは、現在のコードの完全な例を追加しました。それ以外のものはこれまでのところ私がpopupperからCustomPopupにtxt_inputを取得する方法を見つけることができません。 – puputtiap

答えて

0

いくつかのことを変更してみてください:今

class CustomPopup(Popup): 
    txt_input = StringProperty('Text') 

    def __init__(self, txt_input, **kw): 
     super().__init__(**kw) 
     self.txt_input = txt_input 

... 
    def popuper(self, txt_input): 
     popuper = CustomPopup(txt_input) # send txt_input! 
     popuper.open() 

KVファイル

<CustomPopup>: # removed @Popup since you created it in python... 
    size_hint: (.5,.5) 
    auto_dismiss: False 
    title: "af" 
    BoxLayout: 
     orientation: 'vertical' 
     Label: 
      text: root.txt_input 
     Button: 
      text: "Close now" 
      on_press: root.dismiss() 
+0

おかげでYoav、それはトリックでした! – puputtiap

関連する問題