Advertisement
ElliotDG

Untitled

May 19th, 2024
652
0
16 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.74 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.screenmanager import ScreenManager, Screen
  4. from kivy.properties import StringProperty
  5.  
  6. kv = """
  7. #: import NoTransition kivy.uix.screenmanager.NoTransition
  8.  
  9. <Label>
  10.    size_hint: (None, None)
  11.    width: 200
  12.    height: 50
  13.    
  14. <TextInput>
  15.    size_hint: (None, None)
  16.    width: 200
  17.    height: 50
  18.    multiline: False
  19.    write_tab: False
  20.  
  21. <MainMenu>
  22.    GridLayout:
  23.        Button:
  24.            text: "Add to Database"
  25.            size: root.width * .2, root.height * .05
  26.            pos: root.width * .05, root.height * .8
  27.            font_size: root.height * .035
  28.            on_release:
  29.                root.manager.transition = NoTransition()
  30.                root.manager.current = "DatabaseAdd"
  31.        Button:
  32.            text: "Search Database"
  33.            size: root.width * .2, root.height * .05
  34.            pos: root.width * .05, root.height * .7
  35.            font_size: root.height * .035
  36.            on_release:
  37.                root.manager.transition = NoTransition()
  38.                root.manager.current = "SearchDatabase"  # change to root.manager.current
  39.  
  40. <DatabaseAdd>
  41.    name: "DatabaseAdd"
  42.    name_first: id1
  43.    name_last: id2
  44.    #id3: id3
  45.    #id4: id4
  46.    #id5: id5
  47.    #id6: id6
  48.    #id7: id7
  49.    #id8: id8
  50.    AnchorLayout:
  51.        width: root.width
  52.        height: root.height
  53.        ScrollView:
  54.            do_scroll_y: True
  55.            do_scroll_x: False
  56.            size_hint: (None, None)
  57.            size: (root.width * .8, root.height * .8)
  58.            #width: root.width * .80
  59.            #height: root.height * .8
  60.            anchor_x: "center"
  61.            anchor_y: "center"
  62.            GridLayout:
  63.                cols: 1
  64.                GridLayout:
  65.                    cols: 4
  66.                    size_hint_y: None
  67.                    height: self.minimum_height
  68.                    Label:
  69.                        #text: "First Name"
  70.                        text: root.id1Label  # changed to root, and moved property
  71.                    TextInput:
  72.                        id: id1
  73.                    Label:
  74.                        text: "Last Name"
  75.                    TextInput:
  76.                        id: id2
  77.                    #Label:
  78.                        #text: "Value 3"
  79.                    #TextInput:
  80.                        #id: id3
  81.                    #Label:
  82.                        #text: "Value 4"
  83.                    #TextInput:
  84.                        #id: id4
  85.                    #Label:
  86.                        #text: "Value 5"
  87.                    #TextInput:
  88.                        #id: id5
  89.                    #Label:
  90.                        #text: "Value 6"
  91.                    #TextInput:
  92.                        #id: id6
  93.                    #Label:
  94.                        #text: "Value 7"
  95.                    #TextInput:
  96.                        #id: id7
  97.                    #Label:
  98.                        #text: "Value 8"
  99.                    #TextInput:
  100.                        #id: id8
  101.                BoxLayout:
  102.                    size_hint: None, None
  103.                    size: self.minimum_size
  104.                    Label:
  105.                        width: (root.width * .8)/5
  106.                    Button:
  107.                        text: "Submit"
  108.                        width: (root.width * .8)/5
  109.                        on_press: root.press()
  110.                    Label:
  111.                        width: (root.width * .8)/5
  112.                    Button:
  113.                        text: "Clear"
  114.                        width: (root.width * .8)/5
  115.                        on_press: root.clear()
  116.                    Label:
  117.                        width: (root.width * .8)/5
  118.  
  119. <SearchDatabase>:
  120.    Label:
  121.        size_hint: 1, 1
  122.        text: 'Placeholder for search database'
  123.  
  124. WindowManager:
  125.    MainMenu:
  126.    DatabaseAdd:
  127.    SearchDatabase:
  128.        name: "SearchDatabase"
  129.  
  130. """
  131.  
  132.  
  133. class WindowManager(ScreenManager):
  134.     pass
  135.  
  136. class MainMenu(Screen):
  137.     pass
  138.  
  139. class DatabaseAdd(Screen):
  140.     id1Label = StringProperty('First Name')
  141.  
  142.     # def __init__(self, **kwargs):  # __init__ ? Not sure what you want to do here
  143.     #     super().__init__(**kwargs)
  144.     #     self.id1Label = StringProperty("First Name")  Property must be at class level
  145.     #
  146.     def press(self):
  147.         name_first = self.name_first.text
  148.         name_last = self.name_last.text
  149.         print(name_first, name_last)
  150.         self.clear()
  151.  
  152.     def clear(self):
  153.         self.name_first.text = ""
  154.         self.name_last.text = ""
  155.  
  156. class SearchDatabase(Screen):
  157.     pass
  158.  
  159. class MainApp(App):
  160.     def build(self):
  161.         return Builder.load_string(kv)
  162.  
  163. if __name__ == "__main__":
  164.     MainApp().run()
  165.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement