########## # Binarizer ########## # Imported Libraries from tkinter import * from tkinter import ttk # Fonts title = ( "Calibri", 36, "bold" ) # Functions def radio (): choice = var.get () if choice == 1: numberlbl.config (text="Which number would you like to Binarize?") convert.config (state=NORMAL) else: numberlbl.config (text="Which number would you like to DeBinarize?") convert.config (state=NORMAL) entry.config (state=NORMAL) def binarize (n): try: n = int (n) return bin (n) [2:] except: return "ERROR!" def debinarize (n): try: return int (n, 2) except: return "ERROR!" def final (): choice = var.get () inpt = entry.get () if choice == 1: converted = binarize (inpt) output.config (text=str(converted)) else: converted = debinarize (inpt) output.config (text=str(converted)) # Window root = Tk () root.title ("Binarizer") # Variables var = IntVar () entryvar = IntVar () # Title Label Label (root, text=" Binarizer ", font=title).grid (row=0, column=0, columnspan=2) # Radiobuttons ttk.Radiobutton (root, text="Binarizer", variable=var, value=1, command=radio).grid (row=1, column=0, sticky=W) ttk.Radiobutton (root, text="DeBinarizer", variable=var, value=2, command=radio).grid (row=1, column=1, sticky=E) # Quantity Label numberlbl = Label (root, text="Number?") numberlbl.grid (row=2, column=0, sticky=W, columnspan=2) # Entry entry = Entry (root, state=DISABLED, textvariable=entryvar) entry.grid (row=3, column=0, columnspan=2) # Convert Button convert = ttk.Button (root, text="Convert", state=DISABLED, width=40, command=final) convert.grid (row=4, column=0, columnspan=2) # Output Label output = Label (root, text="Converted Number", wraplength=250) output.grid (row=5, column=0, columnspan=2) # Loop root.mainloop ()