2016-09-24 4 views
1

Ich versuche, Bildschirm mit einigen Menüwechselschaltflächen und dann einen verschachtelten Bildschirmmanager zu erstellen, dass ich Bildschirmmanager nur innerhalb des Containers wechseln kann und das Menü außerhalb des Containers intakt lassen. Wenn ich eine Kombination aus Boxlayouts und Gridlayouts verwende, kommt alles übereinander.Kivy Problem mit verschachtelten Screenmanager

from kivy.app import App 
from kivy.uix.boxlayout import BoxLayout 
from kivy.uix.gridlayout import GridLayout 
from kivy.uix.floatlayout import FloatLayout 
from kivy.uix.label import Label 
from kivy.graphics.context_instructions import Color 
from kivy.uix.screenmanager import Screen, ScreenManager 

class ScreenManagement(FloatLayout): 
    pass 

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

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

Kivy Datei:

<[email protected]>: 
    height: '40dp' 
    font_size: 18 

<[email protected]>: 
    height: '40dp' 
    size_hint_y: None 
    font_size: 18 
    write_tab: False 
    multiline: False 
    on_text_validate: root.foo() 

<ScreenManagement>: 
    BoxLayout: 
     orientation: "vertical" 

     BoxLayout: 
      height: "80dp" 
      size_hint_y: None 
      Label: 
       text: 'Patient info Label' 

     BoxLayout: 
      orientation: 'horizontal' 

      BoxLayout: 
       orientation: 'vertical' 
       size_hint_x: 20 

       ToggleButton: 
        text: 'Case Info' 
        group: 'g1' 
        on_screen: 

       ToggleButton: 
        text: 'Modalities' 
        group: 'g1' 

       ToggleButton: 
        text: 'Report Editing' 
        group: 'g1' 

       ToggleButton: 
        text: 'Printing/Exporting' 
        group: 'g1' 

       ToggleButton: 
        text: 'Settings' 
        group: 'g1' 

      BoxLayout: 
       orientation: 'vertical' 
       size_hint_x: 80 

       ScreenManager: 
        id: "Screen1" 

        Screen: 
         name: "Case_info_screen" 

         BoxLayout: 
          orientation: 'vertical' 
          spacing: 20 
          orientation: 'vertical' 
          size_hint: (.5, .5) 
          pos_hint: {'center_x':.5, 'center_y':.5} 

          Label: 
           text: "Case Info" 
           size_hint_y: 25 

          GridLayout: 
           cols: 2 
           padding: 50 
           spacing: 15 
           size_hint_y: 50 

           LabelCases: 
            text: 'First Name: ' 

           TextInputCases: 

           LabelCases: 
            text: 'Last Name: ' 
           TextInputCases: 

           LabelCases: 
            text: 'MRN: ' 
           TextInputCases: 

           LabelCases: 
            text: 'Date of Birth: ' 
           TextInputCases: 

           LabelCases: 
            text: 'Hospital: ' 
           TextInputCases: 

           LabelCases: 
            text: 'Diagnosis: ' 
           TextInputCases: 

          Label: 
           text: "Surgical and Techical Staff" 
           size_hint_y: 25 

       BoxLayout: 

        Button: 
         height: "40dp" 
         size_hint_y: None 
         text: "Back" 
        Button: 
         height: "40dp" 
         size_hint_y: None 
         text: "Next" 

enter image description here

Antwort

0

Sie haben ein Layout verwendet, aber auch wenn Sie die Größe des Layout relativiert die Größen ihrer Kinder wurden feste/statische (height: '40dp'). Wenn Sie size_hint_y: None von TextInputCases entfernen, sehen Sie, was passiert.

Sie kv Code

<[email protected]>: 
    font_size: 18 

<[email protected]>: 
    font_size: 18 
    write_tab: False 
    multiline: False 
    on_text_validate: root.foo() 

<ScreenManagement>: 
    BoxLayout: 
     orientation: "vertical" 

     BoxLayout: 
      height: "80dp" 
      size_hint_y: None 
      Label: 
       text: 'Patient info Label' 

     BoxLayout: 
      orientation: 'horizontal' 

      BoxLayout: 
       orientation: 'vertical' 
       size_hint_x: .20 

       ToggleButton: 
        text: 'Case Info' 
        group: 'g1' 
        on_screen: 

       ToggleButton: 
        text: 'Modalities' 
        group: 'g1' 

       ToggleButton: 
        text: 'Report Editing' 
        group: 'g1' 

       ToggleButton: 
        text: 'Printing/Exporting' 
        group: 'g1' 

       ToggleButton: 
        text: 'Settings' 
        group: 'g1' 

      BoxLayout: 
       orientation: 'vertical' 
       size_hint_x: .80 

       ScreenManager: 
        id: "Screen1" 

        Screen: 
         name: "Case_info_screen" 

         BoxLayout: 
          orientation: 'vertical' 
          spacing: 20 
          orientation: 'vertical' 
          size_hint: (.5, .8) 
          pos_hint: {'center_x':.5, 'center_y':.5} 

          Label: 
           text: "Case Info" 
           size_hint_y: .25 

          GridLayout: 
           cols: 2 
           padding: 50 
           spacing: 15 
           size_hint_y: .70 

           LabelCases: 
            text: 'First Name: ' 

           TextInputCases: 

           LabelCases: 
            text: 'Last Name: ' 
           TextInputCases: 

           LabelCases: 
            text: 'MRN: ' 
           TextInputCases: 

           LabelCases: 
            text: 'Date of Birth: ' 
           TextInputCases: 

           LabelCases: 
            text: 'Hospital: ' 
           TextInputCases: 

           LabelCases: 
            text: 'Diagnosis: ' 
           TextInputCases: 

          Label: 
           text: "Surgical and Techical Staff" 

       BoxLayout: 
        height: "40dp" 
        size_hint_y: None 
        Button: 
         text: "Back" 
        Button: 
         text: "Next" 

Aber ich würde eher empfehlen so etwas wie Scroll zu machen -> Gridlayout -> alle Kinder, so dass Sie die Inhalte mit einer festen Größe (mit einer Fähigkeit zu blättern) haben können und bewahren Sie das "iframe" -ähnliche Layout. ^^

Verwandte Themen