2
\$\begingroup\$

I'm really struggling to understand application of classes and best practices in fairly advanced level GUIs, and such an example could be extremely helpful. Please note that this is my first GUI implementation and almost first Python implementation, and its working well. But the source code is ugly and long and definitely not how the code is supposed to be written.

from tkinter import *
import json

def guier():    
    #Indent four spaces
    gParmDict = {'var01': 1,
                 'var02': 'ABCD',
                 'var03': 'EFG',
                 'var04': 2.0,
                 'var05': 0.1,
                 'var06': 0.1,
                 'var07': 0.05,
                 'var08': 35,
                 'var09': 1.2,
                 'var10': 0.1,
                 'var11': 100.0,
                 'var12': 0.35,
                 'var13': 0.05,
                 'var14': 2.0,
                 'var15': 100.0}


    # Root Box
    #---------------------------------------------------------------------------------
    gRoot = Tk()
    gRoot.configure(background='#696969')
    gRoot.title('Alpha (build 0.01)')
    gRoot.geometry('1140x690')
    gRoot.resizable(False, False)

    # Top Left Box
    #---------------------------------------------------------------------------------
    lFrameLT = Frame(gRoot, width=300, height=500, bg = 'silver')
    lFrameLT.grid(row = 0, column = 0, padx = 5, pady = 5, ipadx = 5, ipady = 5)
    lFrameLT.grid_propagate(0)
    lFrameLT.grid_columnconfigure (0, weight = 1)
    Label(lFrameLT, text = "Algorithms", bg = '#313233', fg = '#FFFFFF', anchor = 'w', font='Helvetica 8 bold').grid(row = 0, column = 0, columnspan = 2, sticky = 'NSEW')

    var01Hold = IntVar()
    var01Hold.set(gParmDict['var01'])

    Radiobutton(lFrameLT, text='''Algorithm 1:                                                           ''', variable=var01Hold, value=1, indicatoron = 1).grid(row = 1, column = 0, padx = (20, 5), pady = (20, 0), sticky = 'W')
    Label(lFrameLT, text='''Description of algo 1 xxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxxxx xxxxxxxx xxxxxxxxxx''',
    justify = LEFT, bg = 'silver', fg = 'grey', wraplength = 265, font='Helvetica 8').grid(row = 2, column = 0, padx = (20, 5), pady = (0, 10), sticky = 'W')

    Radiobutton(lFrameLT, text='''Algorithm 2:                                                           ''', variable=var01Hold, value=2, indicatoron = 1).grid(row = 3, column = 0, padx = (20, 5), pady = (0, 0), sticky = 'W')
    Label(lFrameLT, text='''Description of algo 2 xxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxxxx xxxxxxxx xxxxxxxxxx''',
    justify = LEFT, bg = 'silver', fg = 'grey', wraplength = 265, font='Helvetica 8').grid(row = 4, column = 0, padx = (20, 5), pady = (0, 10), sticky = 'W')

    Radiobutton(lFrameLT, text='''Algorithm 3:                                                           ''', variable=var01Hold, value=3, indicatoron = 1).grid(row = 5, column = 0, padx = (20, 5), pady = (0, 0), sticky = 'W')
    Label(lFrameLT, text='''Description of algo 3 xxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxxxx xxxxxxxx xxxxxxxxxx''',
    justify = LEFT, bg = 'silver', fg = 'grey', wraplength = 265, font='Helvetica 8').grid(row = 6, column = 0, padx = (20, 5), pady = (0, 10), sticky = 'W')

    Radiobutton(lFrameLT, text='''Algorithm 4:                                                           ''', variable=var01Hold, value=4, indicatoron = 1).grid(row = 7, column = 0, padx = (20, 5), pady = (0, 0), sticky = 'W')
    Label(lFrameLT, text='''Description of algo 4 xxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxxxx xxxxxxxx xxxxxxxxxx''',
    justify = LEFT, bg = 'silver', fg = 'grey', wraplength = 265, font='Helvetica 8').grid(row = 8, column = 0, padx = (20, 5), pady = (0, 10), sticky = 'W')

    # Bottom Left Box
    #--------------------------------------------------------------------------------------

    lFrameLB = Frame(gRoot, width=300, height=150, bg = 'silver')
    lFrameLB.grid(row = 1, column = 0, padx = 5, pady = 5, ipadx = 5, ipady = 5)
    lFrameLB.grid_propagate(0)
    lFrameLB.grid_columnconfigure (0, weight = 1)
    Label(lFrameLB, text = "Control", bg = '#313233', fg = '#FFFFFF', anchor = 'w', font='Helvetica 8 bold').grid(row = 0, column = 0, columnspan = 4, sticky = 'NSEW')

    Button(lFrameLB, text = "Test Algorithm", command = print("Test in progress")).grid(row = 1, column = 1, sticky = 'NSEW', padx = (5, 20), pady = (10, 10))
    Button(lFrameLB, text = "Activate Algorithm", command = print("Algo live...")).grid(row = 1, column = 3, sticky = 'NSEW', padx = (5, 20), pady = (10, 10))

    # Top Right Box
    #--------------------------------------------------------------------------------------

    lFrameRT = Frame(gRoot, width=800, height=500, bg = 'silver')
    lFrameRT.grid(row = 0, column = 1, padx = 5, pady = 5, ipadx = 5, ipady = 5)
    lFrameRT.grid_propagate(0)
    lFrameRT.grid_columnconfigure (0, weight = 1)
    Label(lFrameRT, text = "Parameters", bg = '#313233', fg = '#FFFFFF', anchor = 'w', font='Helvetica 8 bold').grid(row = 0, column = 0, columnspan = 6, sticky = 'NSEW')

    var02Hold = StringVar()
    var02Hold.set(gParmDict['var02'])
    Label(lFrameRT, text = "Base method:", bg = 'silver').grid(row = 1, column = 0, padx = (20, 5), pady = (20, 0), sticky = 'E')
    Entry(lFrameRT, width = 10, textvariable = var02Hold, justify = 'center').grid(row = 1, column = 1, padx = (5, 20), pady = (20, 0), sticky = 'W')

    var03Hold = StringVar()
    var03Hold.set(gParmDict['var03'])
    Label(lFrameRT, text = "Target method:", bg = 'silver').grid(row = 2, column = 0, padx = (20, 5), pady = (20, 0), sticky = 'E')
    Entry(lFrameRT, width = 10, textvariable = var03Hold, justify = 'center').grid(row = 2, column = 1, padx = (5, 20), pady = (20, 0), sticky = 'W')

    var04Hold = DoubleVar()
    var04Hold.set(gParmDict['var04'])
    Label(lFrameRT, text = "Goal [%]:", bg = 'silver').grid(row = 1, column = 2, padx = (20, 5), pady = (20, 0), sticky = 'E')
    Entry(lFrameRT, width = 10, textvariable = var04Hold, justify = 'center').grid(row = 1, column = 3, padx = (5, 20), pady = (20, 0), sticky = 'W')

    var05Hold = DoubleVar()
    var05Hold.set(gParmDict['var05'])
    Label(lFrameRT, text = "Test Backup [Days]:", bg = 'silver').grid(row = 2, column = 2, padx = (20, 5), pady = (20, 0), sticky = 'E')
    Entry(lFrameRT, width = 10, textvariable = var05Hold, justify = 'center').grid(row = 2, column = 3, padx = (5, 20), pady = (20, 0), sticky = 'W')

    var06Hold = DoubleVar()
    var06Hold.set(gParmDict['var06'])
    Label(lFrameRT, text = "Cost factors [%]:", bg = 'silver').grid(row = 1, column = 4, padx = (20, 5), pady = (20, 0), sticky = 'E')
    Entry(lFrameRT, width = 10, textvariable = var06Hold, justify = 'center').grid(row = 1, column = 5, padx = (5, 20), pady = (20, 0), sticky = 'W')

    var07Hold = DoubleVar()
    var07Hold.set(gParmDict['var07'])
    Label(lFrameRT, text = "Cost factor2 [%]:", bg = 'silver').grid(row = 2, column = 4, padx = (20, 5), pady = (20, 0), sticky = 'E')
    Entry(lFrameRT, width = 10, textvariable = var07Hold, justify = 'center').grid(row = 2, column = 5, padx = (5, 20), pady = (20, 0), sticky = 'W')

    lFrameRTB = Frame(lFrameRT, width=700, height=320, bg = 'dark grey')
    lFrameRTB.grid(row = 3, column = 0, padx = 20, pady = (20, 10), ipadx = 5, ipady = 5, columnspan = 6, sticky = 'NSEW')
    lFrameRTB.grid_propagate(0)

    Label(lFrameRTB, text = "SITUATION 1", width = 10, bg = 'dark orange', fg = 'white', font = 'helvatica 8 bold').grid(row = 0, column = 0, columnspan = 2, sticky = 'NSEW')

    var08Hold = IntVar()
    var08Hold.set(gParmDict['var08'])
    Label(lFrameRTB, text = "Drive [Minutes]:", bg = 'dark grey').grid(row = 1, column = 0, padx = (20, 5), pady = (10, 0), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var08Hold, justify = 'center').grid(row = 1, column = 1, padx = (5, 20), pady = (10, 0), sticky = 'W')

    var09Hold = DoubleVar()
    var09Hold.set(gParmDict['var09'])
    Label(lFrameRTB, text = "Minimum drop [%]:", bg = 'dark grey').grid(row = 2, column = 0, padx = (20, 5), pady = (10, 0), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var09Hold, justify = 'center').grid(row = 2, column = 1, padx = (5, 20), pady = (10, 0), sticky = 'W')

    var10Hold = DoubleVar()
    var10Hold.set(gParmDict['var10'])
    Label(lFrameRTB, text = "Min rise [%]:", bg = 'dark grey').grid(row = 3, column = 0, padx = (20, 5), pady = (10, 0), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var10Hold, justify = 'center').grid(row = 3, column = 1, padx = (5, 20), pady = (10, 0), sticky = 'W')

    var11Hold = DoubleVar()
    var11Hold.set(gParmDict['var11'])
    Label(lFrameRTB, text = "Proportion [%]:", bg = 'dark grey').grid(row = 4, column = 0, padx = (20, 5), pady = (10, 20), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var11Hold, justify = 'center').grid(row = 4, column = 1, padx = (5, 20), pady = (10, 20), sticky = 'W')

    Label(lFrameRTB, text = "SITUATION 2", width = 10, bg = 'dark blue', fg = 'white', font = 'helvatica 8 bold').grid(row = 0, column = 3, columnspan = 2, sticky = 'NSEW')

    var12Hold = DoubleVar()
    var12Hold.set(gParmDict['var12'])
    Label(lFrameRTB, text = "Minimum [%]:", bg = 'dark grey').grid(row = 1, column = 3, padx = (20, 5), pady = (10, 0), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var12Hold, justify = 'center').grid(row = 1, column = 4, padx = (5, 20), pady = (10, 0), sticky = 'W')

    var13Hold = DoubleVar()
    var13Hold.set(gParmDict['var13'])
    Label(lFrameRTB, text = "Maximum [%]:", bg = 'dark grey').grid(row = 2, column = 3, padx = (20, 5), pady = (10, 0), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var13Hold, justify = 'center').grid(row = 2, column = 4, padx = (5, 20), pady = (10, 0), sticky = 'W')

    var14Hold = DoubleVar()
    var14Hold.set(gParmDict['var14'])
    Label(lFrameRTB, text = "Stop [%]:", bg = 'dark grey').grid(row = 3, column = 3, padx = (20, 5), pady = (10, 0), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var14Hold, justify = 'center').grid(row = 3, column = 4, padx = (5, 20), pady = (10, 0), sticky = 'W')

    var15Hold = DoubleVar()
    var15Hold.set(gParmDict['var15'])
    Label(lFrameRTB, text = "Move [%]:", bg = 'dark grey').grid(row = 4, column = 3, padx = (20, 5), pady = (10, 20), sticky = 'E')
    Entry(lFrameRTB, width = 10, textvariable = var15Hold, justify = 'center').grid(row = 4, column = 4, padx = (5, 20), pady = (10, 20), sticky = 'W')

    lFrameRTBM = Frame(lFrameRTB, width=275, height=320, bg = 'grey')
    lFrameRTBM.grid(row = 0, column = 2, rowspan = 5, padx = 5, ipadx = 5, ipady = 5, sticky = 'NSEW')
    lFrameRTBM.grid_propagate(0)

    # Botom Right Box
    #--------------------------------------------------------------------------------------

    lFrameRB = Frame(gRoot, width=800, height=150, bg = 'silver')
    lFrameRB.grid(row = 1, column = 1, padx = 5, pady = 5, ipadx = 5, ipady = 5)
    lFrameRB.grid_propagate(0)
    lFrameRB.grid_columnconfigure (0, weight = 1)
    Label(lFrameRB, text = "Results", bg = '#313233', fg = '#FFFFFF', anchor = 'w', font='Helvetica 8 bold').grid(row = 0, column = 0, columnspan = 2, sticky = 'NSEW')

    Label(lFrameRB, text = "RB").grid(row = 1, column = 0, sticky = 'NW')

    gRoot.mainloop()
guier()
\$\endgroup\$
  • \$\begingroup\$ Welcome to Code Review, please edit the title to reflect what the program actually does - lots of code here uses Python or Tkinter, it doesn't help to distinguish this post from others. Apart from that hope you get some more good answers, enjoy your stay! \$\endgroup\$ – ferada Oct 28 '18 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.