tk_dashboard.py

# =========================================================
# my dashboard
# =========================================================
# lot of things to do:
# - pick the status values to display
# - display status values
# - make it pretty
# - add a timer (every second?)
# - status button is for testing/debuging
#   comment it out when done (keep the code for future?)
# ---------------------------------------------------------
# look at the 'after' method to create an infinite loop
# with a delay.
# ---------------------------------------------------------
# good project to test students?
# =========================================================

# ---------------------------------------------------------
# import
# ---------------------------------------------------------

import sys

if sys.version_info.major is 3:
    from tkinter import *
    py3 = True
else:
    from Tkinter import *
    py3 = False

# ---------------------------------------------------------
# global variables
# ---------------------------------------------------------

buttonFont  = ('arial', '15', 'bold')
statusFont  = ('arial', '15', 'normal')
textFont    = ('arial', '15', 'normal')
titleFont   = ('arial', '15', 'bold')

statusBg    = 'white'

# ---------------------------------------------------------
# functions
# ---------------------------------------------------------

# --- exit program function -------------------------------

def quit():
    sys.exit()

# --- update status values in dashboard -------------------

def updateStatus():
    pass

# --- create status display (one per status item) ---------

def statusDisplay(fs, r, text):

    l1 = Label(fs, text=text, font=statusFont, 
            padx=8, pady=4, relief='groove',
            borderwidth=2, anchor='e', bg=statusBg)
    l1.grid(row=r, column=0, sticky=E+W)

    l2 = Label(fs, text='status goes here', font=statusFont,
            padx=8, pady=4, relief='groove',
            borderwidth=2, anchor='w', bg=statusBg)
    l2.grid(row=r, column=1, sticky=E+W)

    return l2

# --- create dashboard ------------------------------------

def dashBoard(root):

    # --- root frame to hold everything

    f = Frame(root)
    f.grid(row=0,column=0)

    # --- dashboard title

    l1 = Label(f, text='Dashboard', font=titleFont)
    l1.grid(row=0, column=0, sticky=N+E+W)

    # -- status displays

    fs = Frame(f)
    fs.grid(row=1, column=0)

    statusDisplay(fs, 0, 'Great status display')
    statusDisplay(fs, 1, 'Even Greater status display')
    statusDisplay(fs, 2, 'status display')

    # --- quit button

    fq = Frame(f)
    fq.grid(row=2, column=0)
    bq = Button(fq, text='Quit', font=buttonFont,
            command=quit) 
    bq.grid(row=0, column=0)

    bu = Button(fq, text='Update Status', font=buttonFont,
            command=updateStatus)
    bu.grid(row=0, column=1)


# ---------------------------------------------------------
# main
# ---------------------------------------------------------

if __name__ == '__main__':

    root = Tk()
    root.title('Dashboard')

    dashBoard(root)

    root.mainloop()