Reputation: 89
I am a beginner in python especially in kivy. I am facing some small issues in designing a GUI. As per the diagram(I have attached) in the page, I am unable to put label, TextInput in proper format. Can you help me? Thanks in advance.
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem
from kivy.lang import Builder
from kivy.uix.checkbox import CheckBox
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.button import Button
from kivy.app import App
from kivy.uix.textinput import TextInput
Builder.load_string("""
<Test>:
do_default_tab: False
TabbedPanelItem:
text: 'page1'
BoxLayout:
Label:
text: 'label'
Label:
text: 'entry'
TextInput:
text: 'Entry'
TextInput:
text: 'Entry'
CheckBox:
text: 'CheckBox'
Button:
text: 'button'
TabbedPanelItem:
text: 'page2'
BoxLayout:
Label:
text: 'label'
TextInput:
text: 'entry'
Label:
text: 'label'
TextInput:
text: 'entry'
Button:
text: 'button'
""")
class Test(TabbedPanel):
pass
class MyApp(App):
def build(self):
test = Test()
panel = TabbedPanelItem()
test.add_widget(panel)
return test
if __name__ == '__main__':
MyApp().run()
Upvotes: 0
Views: 2682
Reputation: 286
You are putting your widgets (Label, TextInput, CheckBox, Button...) in a BoxLayout, the behaviour of BoxLayout is to group widgets into a (only one) column or row, you can change the orientation of the BoxLayout setting the attr 'orientation', by default 'horizontal'. (read this)
You can put one BoxLayout into other BoxLayout, and setting the orientation you can create diferent things, for you page1 you can do something like this:
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
Label:
text: 'label'
TextInput:
text: 'Entry'
CheckBox:
text: 'CheckBox'
Button:
text: 'button'
BoxLayout:
orientation: 'horizontal'
Label:
text: 'label'
TextInput:
text: 'Entry'
CheckBox:
text: 'CheckBox'
Button:
text: 'button'
Like Mox said in comments, maybe GridLayout works fine for your app.
If you are beginner in kivy I recommend you watch this videos from Alexander Taylor, one of the core developers of kivy.
Upvotes: 4