2016-03-28 25 views
0

numaralı telefona otomatik olarak yükleyebildiğiniz bir uygulama ekranı oluşturmak için textinput kutularını kullanarak genel profil bilgilerini (ad, yükseklik, ağırlık, vb ..) girebileceğiniz bir profil hazırlıyorum. Bilgiyi kaydetmek için her textinput kutusunun yanında bir düğme koymanın ve bilgiyi yüklemek için başka bir düğmeye basmanın bir yolu olduğunu biliyorum. Kullanıcı bu bilgiyi, bir düğmeye basarak bilgileri manuel olarak yüklemek yerine uygulamayı açtığında otomatik olarak yüklemek için bir yol olup olmadığını merak ediyorum.Kullanıcı bilgilerini kivy

<Phone>: 
result: _result 
h: _h 
w: _w 


AnchorLayout: 
    anchor_x: 'center' 
    anchor_y: 'top' 

    ScreenManager: 
     size_hint: 1, .9 
     id: _screen_manager 
     Screen: 
      name: 'home' 
      canvas.before: 
       Rectangle: 
        pos: self.pos 
        size: self.size 
        source: "/home/aaron/Desktop/main.png" 
      Label: 
       markup: True 
       text: '[size=100][color=ff3333]Welcome to [color=ff3333]Diabetes Manager[/color][/size]' 
     Screen: 
      name: 'menu' 
      GridLayout: 
       cols: 2 
       padding: 50 
       canvas.before: 
        Rectangle: 
         pos: self.pos 
         size: self.size 
         source: "/home/aaron/Desktop/main.png" 

       Button: 
        text: 'My Profile' 
        on_press: _screen_manager.current = 'profile' 
       Button: 
        text: 'History' 
        on_press: _screen_manager.current = 'history'  

       Button: 
        text: 'New Entry' 
        on_press: _screen_manager.current = 'new_entry' 
       Button: 
        text: 'Graph' 
        on_press: _screen_manager.current = 'graph' 
       Button: 
        text: 'Diet' 
        on_press: _screen_manager.current = 'diet' 
       Button: 
        text: 'Settings' 
        on_press: _screen_manager.current = 'settings' 

     Screen: 
      name: 'profile' 
      GridLayout: 
       cols: 1 
       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]Name[/color][/size]' 
        TextInput: 
         id: _name 
         hint_text: 'Name' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]Gender[/color][/size]' 
        TextInput: 
         id: _gender1 
         hint_text: 'Gender' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=34][color=0000ff]Type of Diabetes[/color][/size]' 
        TextInput: 
         id: _type 
         hint_text: 'Type of Diabetes' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]Height (in)[/color][/size]' 
        TextInput: 
         id: _h 
         hint_text: 'Height in inches' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]Weight (lb)[/color][/size]' 
        TextInput: 
         id: _w 
         hint_text: 'Weight in pounds' 

       BoxLayout: 
        Button: 
         text: 'Calculate BMI' 
         on_press: root.product(*args) 

        Label: 
         size_hint_x: 4.5 
         id:_result 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]BMI[/color][/size]' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=30][color=0000ff]List of Medications[/color][/size]' 
        TextInput: 
         id: _meds 
         hint_text: 'List of Medications' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=38][color=0000ff]Insulin Times[/color][/size]' 
        TextInput: 
         id: _times 
         hint_text: 'Please Enter Times to Take Insulin' 


     Screen: 
      name: 'history' 
      GridLayout: 
       cols:1 

     Screen: 
      name: 'new_entry' 
      GridLayout: 
       cols:1 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]Time[/color][/size]' 
        TextInput: 
         id: _time 
         hint_text: 'Current Time' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=28][color=0000ff]Blood Sugar (mg/dL)[/color][/size]' 
        TextInput: 
         id: _glucose_reading 
         hint_text: 'Current Blood Sugar' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=40][color=0000ff]Carbs[/color][/size]' 
        TextInput: 
         id: _food 
         hint_text: 'Total Carbs for meal' 

       BoxLayout: 
        Label: 
         size_hint_x: 0.22 
         bold: True 
         markup: True 
         text: '[size=30][color=0000ff]Medications Taken[/color][/size]' 
        TextInput: 
         id: _meds_taken 
         hint_text: 'Please Enter Any Medications Taken' 


     Screen: 
      name: 'graph' 
      GridLayout: 
       cols: 3 
       padding: 50 
      Label: 
       markup: True 
       text: '[size=24][color=dd88ff]Your Graph[/color][/size]' 

     Screen: 
      name: 'diet' 
      GridLayout: 
       cols: 3 
       padding: 50 
      Label: 
       markup: True 
       text: '[size=24][color=dd88ff]Reccomended Diet[/color][/size]' 


     Screen: 
      name: 'settings' 
      GridLayout: 
       cols: 3 
       padding: 50 
      Label: 
       markup: True 
       text: '[size=24][color=dd88ff]Settings[/color][/size]' 


AnchorLayout: 
    anchor_x: 'center' 
    anchor_y: 'bottom' 
    BoxLayout: 
     orientation: 'horizontal' 
     size_hint: 1, .1 
     Button: 
      id: btnExit 
      text: 'Exit' 
      on_press: app.stop() 
     Button: 
      text: 'Menu' 
      on_press: _screen_manager.current = 'menu' 

cevap

2

Bir json içinde bilgilerinizi kaydedebilirsiniz (ithalat json) dosyası ve on_start olay yöntemi kullanılarak yükleyin.

1

Eh, build() işlevi bir kök widget'ı bekliyor her App başlar iade edilecek, böylece ya sizin App sınıf içindeki bir işleve sahip basit bir dosya yükleme yapmak ve her birine değerleri zorlayabilir ids üzerinden veya root widget'tan widget'ı children

ya da güncellemek istediğiniz pencere öğesi değerlerinin bulunduğu sınıfın __init__() içindeki aynı yükleme işlevini yapın.

Örneğin, class MyBox(BoxLayout), güncellemek istediğiniz değerlerin bulunduğu bir sınıftır. Ardından, yükleme işlevinizi MyBox.__init__() içinde arayın. Daha da basitleştirebilirsiniz: __init__() içindeki yükleme işlevini kullanın ve değerleri ileteceğiniz bir liste/sözlük/değişken oluşturun. kv dosyasında, değişkenlere sadece root.<variable> aracılığıyla erişebilirsiniz.

2

Kivy, standart ini dosyalarını ayrıştırmak için subclass of ConfigParser kullanır. app-specific settings'u yüklemek için nasıl kullanılacağı hakkında belgeler, kivy.app doc sayfasındadır. Dokümanlar

:

class TestApp(App): 
    def build_config(self, config): 
     config.setdefaults('section1', { 
      'key1': 'value1', 
      'key2': '42' 
     }) 

    def build(self): 
     config = self.config 
     return Label(text='key1 is %s and key2 is %d' % (
      config.get('section1', 'key1'), 
      config.getint('section1', 'key2'))) 
+0

Ben tamamen bu seçenek hakkında unuttun! O_o – KeyWeeUsr

+0

Bunu yapmayı nasıl yaparsınız? Kivy dosyasına girdim – Azaro

İlgili konular