"""Get entry from field and calculate the color."""
    input_str = entry.get()
    try:
        hertz = float(input_str)
    except ValueError:
        SHELL.msgtxt.set('Type Error')
        return -1
    hertz = decimal.Decimal(hertz)
    emw = EMWave(hertz)
    SHELL.msgtxt.set(str(emw))
    try:
        SHELL.msg.config(bg=str(emw).split()[0])
    except tk.TclError:
        SHELL.msg.config(bg='#D9D9D9')

SHELL = TkTemplate()
SHELL.main_window.title('EM Spectrum by Hz')
SHELL.msg.config(font=('sans', 12))

frame = tk.Frame(SHELL.main_window)
label = tk.Label(frame, text='Hz')
entry = tk.Entry(frame, width=6)
button = tk.Button(frame, text='Analyze wave', command=calc)

frame.pack()
label.pack(side='left')
entry.pack(side='left')
button.pack(padx=20)
SHELL.center_window(height_=220, width_=250)

if __name__ == '__main__':
Example #2
0
def change_colour(name_or_hex):
    """
    Takes color name or hex color as an argument,
    and turns the window that color.
    """
    try:
        SHELL.main_window.config(bg=name_or_hex)
        pane.config(bg=name_or_hex)

    #build this into shell
    except tk.TclError:
        tkMessageBox.showerror('Color error', 'That color is unknown.')

SHELL = TkTemplate()
SHELL.main_window.title('Colors by Hex or Name')

#build this in
SHELL.msg.destroy()

pane = tk.Frame(SHELL.main_window)
entry = tk.Entry(pane, width=15, font=('sans', 12))
bottom = tk.Button(
    pane, text="Change Color", command=lambda: change_colour(entry.get()))
entry.pack(side=tk.LEFT)
bottom.pack(side=tk.RIGHT)
pane.pack(fill=tk.X, side=tk.BOTTOM, pady=10, padx=10)

TkTemplate.center_window(height_=50, width_=300)
if __name__ == '__main__':
    SHELL.main_window.mainloop()