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 1: Line 1:
 
= What =
 
= What =
  
I am trying to implement an older window of mine from [[Python Smart Terminal]], done in Tkinter over again in Kivy.  This is my first bit of code to show some progress, I am trying to do it without any Kv coding.  [[Kivy - First Impressions]]
+
I am trying to implement this window in Tkinter over again in Kivy.  This is my first bit of code to show some progress, I am trying to do it without any Kv coding.  [[]]
  
= Tkinter =
+
Here is the [[SmartTerminal]] window.
  
Here is the [[SmartTerminal]] window in Tkinter.
 
  
[[File:Screen_shot.png | 1000x2500px]]
 
 
= Kivi ( first try ) =
 
And here is the first Kivy windows that shows just a bit of progress.  Not much, but the basic outline of the Tkinter code.  One of the most useful references was [https://www.blog.pythonlibrary.org/2013/11/25/kivy-101-how-to-use-boxlayouts/ Mouse vs Python ]
 
 
[[File:Gui 1a.png| 1000x2500px]]
 
 
= Python Code =
 
 
Less than great, but something
 
<pre>
 
 
# -*- coding: utf-8 -*-
 
 
import kivy
 
import random
 
 
from kivy.app            import App
 
 
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)