Editing Kivy vs Tkinter - First Try

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 16: Line 16:
 
= Python Code =
 
= Python Code =
  
Less than great, but something
+
<!-----------
<pre>
+
this cannot bee seen
 +
------------->
  
# -*- coding: utf-8 -*-
 
  
import kivy
 
import random
 
  
from kivy.app            import App
+
[[Category:Draft]] [[Category:Arduino/RaspberryPi]] [[Category:SCIL]]
 
 
from kivy.uix.boxlayout  import BoxLayout
 
from kivy.uix.gridlayout import GridLayout
 
 
 
from kivy.uix.button    import Button
 
from kivy.uix.textinput  import TextInput
 
from kivy.uix.label      import Label
 
from kivy.uix.dropdown  import DropDown
 
 
 
# color declarations, see doc in ??
 
red    = [1,0,0,1]
 
green  = [0,1,0,1]
 
blue    = [0,0,1,1]
 
purple  = [1,0,1,1]
 
 
 
 
 
########################################################################
 
class GUI(App):
 
    """
 
    My first non trivial ( not by much example )
 
    """
 
    #----------------------------------------------------------------------
 
    def build(self):  # seems to be called automagically lets treat like init for now
 
        """
 
        Build all stuff here, will call frames after Tkinter, but of course they are really layouts
 
        """
 
        root          = BoxLayout( padding=10, orientation="vertical" )
 
 
 
        a_frame = self.__make_parm_frame__()
 
        root.add_widget( a_frame    )
 
 
 
        a_frame = self.__make_button_frame__()
 
        root.add_widget( a_frame    )
 
 
 
        a_frame = self.__make_send_frame__()
 
        root.add_widget( a_frame )
 
 
 
        a_frame = self.__make_rec_frame__()
 
        root.add_widget( a_frame )
 
 
 
        return  root
 
 
 
    # ------ ------------
 
    def __make_parm_frame__( self  ):
 
 
 
        max_cols    = 3
 
 
 
        a_layout = BoxLayout( padding=10 )  # default horizontal
 
 
 
        for i in range( max_cols ):
 
            lbl      = Label(text='Parameter')
 
            a_layout.add_widget( lbl    )
 
 
 
        return a_layout
 
 
 
    # ------ ------------
 
    def __make_button_frame__( self  ):
 
 
 
        colors      = [red, green, blue, purple]
 
        max_cols    = 3
 
 
 
        a_layout = BoxLayout( padding=10 )
 
 
 
        for i in range( max_cols ):
 
            btn = Button(text="Button #%s" % (i+1),
 
                        background_color=random.choice(colors)
 
                        )
 
            a_layout.add_widget( btn    )
 
 
 
        return a_layout
 
 
 
    # ------ ------------
 
    def __make_send_frame__( self  ):
 
 
 
        colors      = [red, green, blue, purple]
 
        max_cols    = 3
 
 
 
        a_layout = BoxLayout( padding=10 )
 
 
 
        for i in range( max_cols ):
 
            btn = Button(text="Button #%s" % (i+1),
 
                        background_color=random.choice(colors)
 
                        )
 
            a_layout.add_widget( btn    )
 
 
 
            txt_in  = TextInput(  )
 
 
 
            a_layout.add_widget( txt_in )
 
 
 
        return a_layout
 
 
 
    # ------------------------------------------
 
    def __make_rec_frame__( self, ):
 
 
 
        a_layout = BoxLayout( padding=10 )
 
 
 
        txt_in  = TextInput(  )
 
 
 
        a_layout.add_widget( txt_in )
 
        return a_layout
 
 
 
#----------------------------------------------------------------------
 
if __name__ == "__main__":
 
    app = GUI()
 
    app.run()
 
 
 
</pre>
 
  
  

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)