|
|
@ -11,33 +11,33 @@ app = Window(root)
|
|
|
|
|
|
|
|
|
|
|
|
def add_base():
|
|
|
|
def add_base():
|
|
|
|
out = []
|
|
|
|
out = []
|
|
|
|
for x in baseDropdown['values']:
|
|
|
|
for x in baseList['values']:
|
|
|
|
out.append(int(x))
|
|
|
|
out.append(int(x))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if not int(baseInput.get()) in out:
|
|
|
|
if not int(baseInput.get()) in out:
|
|
|
|
out.append(int(baseInput.get()))
|
|
|
|
out.append(int(baseInput.get()))
|
|
|
|
baseDropdown['values'] = sorted(out)
|
|
|
|
baseList['values'] = sorted(out)
|
|
|
|
functionTrigger(0,0,0) # Trigger number conversion if a base is added
|
|
|
|
functionTrigger(0,0,0) # Trigger number conversion if a base is added
|
|
|
|
except ValueError:
|
|
|
|
except ValueError:
|
|
|
|
print("Not a valid base!")
|
|
|
|
listOut.delete(0,listOut.size())
|
|
|
|
lbl1 = Label(root, text="\nInvalid base!", font=("Arial", 12))
|
|
|
|
listOut.insert(END, "Not a valid base!")
|
|
|
|
lbl1.grid(column=1, row=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def functionTrigger(a,b,c): # Positional arguments from the trace are not needed for this program, but still must be defined
|
|
|
|
def functionTrigger(a,b,c): # Positional arguments from the trace are not needed for this program, but still must be defined
|
|
|
|
input = numberInput.get()
|
|
|
|
input = numberInput.get()
|
|
|
|
base = int(baseDropdown['values'][baseDropdown.current()]) # Retreive the current selected base
|
|
|
|
base = int(baseList['values'][baseList.current()]) # Retreive the current selected base
|
|
|
|
baseConverter(input, base)
|
|
|
|
baseConverter(input, base)
|
|
|
|
|
|
|
|
|
|
|
|
def baseConverter(userInput, numberBase):
|
|
|
|
def baseConverter(userInput, numberBase):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
decimalNum = int(userInput,numberBase) # First attempt to get the number in decimal.
|
|
|
|
decimalNum = int(userInput,numberBase) # First attempt to get the number in decimal.
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
print("Number entered does not match the base!")
|
|
|
|
listOut.delete(0,listOut.size())
|
|
|
|
|
|
|
|
listOut.insert(END, "Number entered does not match the base!")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
outputText = ""
|
|
|
|
listOut.delete(0,listOut.size())
|
|
|
|
for base in baseDropdown['values']: # Iterate through all bases
|
|
|
|
for base in baseList['values']: # Iterate through all bases
|
|
|
|
outputText += "Base " + base + ": "
|
|
|
|
outputText = "Base " + base + ": "
|
|
|
|
outputNumber = ""
|
|
|
|
outputNumber = ""
|
|
|
|
tempNum = decimalNum
|
|
|
|
tempNum = decimalNum
|
|
|
|
while tempNum > 0:
|
|
|
|
while tempNum > 0:
|
|
|
@ -48,9 +48,9 @@ def baseConverter(userInput, numberBase):
|
|
|
|
else: # Alphanumeric characters needed
|
|
|
|
else: # Alphanumeric characters needed
|
|
|
|
outputNumber += chr(55 + digit) # ASCII character offset for capital letters
|
|
|
|
outputNumber += chr(55 + digit) # ASCII character offset for capital letters
|
|
|
|
outputNumber = outputNumber[::-1]
|
|
|
|
outputNumber = outputNumber[::-1]
|
|
|
|
outputText += outputNumber + "\n"
|
|
|
|
outputText += outputNumber
|
|
|
|
lblOut = Label(root, text=outputText, font=("Arial", 12))
|
|
|
|
listOut.insert(END, outputText)
|
|
|
|
lblOut.grid(column=0, row=7)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root.wm_title("Numerical converter")
|
|
|
|
root.wm_title("Numerical converter")
|
|
|
|
|
|
|
|
|
|
|
@ -75,10 +75,10 @@ separator1.place(relx=0, rely=0.2, relwidth=1, relheight=1)
|
|
|
|
separator2 = Separator(root, orient='horizontal')
|
|
|
|
separator2 = Separator(root, orient='horizontal')
|
|
|
|
separator2.place(relx=0, rely=0.43, relwidth=1, relheight=1)
|
|
|
|
separator2.place(relx=0, rely=0.43, relwidth=1, relheight=1)
|
|
|
|
|
|
|
|
|
|
|
|
baseDropdown = Combobox(root)
|
|
|
|
baseList = Combobox(root, width='10')
|
|
|
|
baseDropdown['values']= (2, 10, 16)
|
|
|
|
baseList['values']= (2, 10, 16)
|
|
|
|
baseDropdown.current(1) #set the selected item
|
|
|
|
baseList.current(1) #set the selected item
|
|
|
|
baseDropdown.grid(column=1, row=4)
|
|
|
|
baseList.grid(column=1, row=4)
|
|
|
|
lbl3 = Label(root, text="\nNumber Base \n of the input:\n", font=("Arial", 12))
|
|
|
|
lbl3 = Label(root, text="\nNumber Base \n of the input:\n", font=("Arial", 12))
|
|
|
|
lbl3.grid(column=0, row=4)
|
|
|
|
lbl3.grid(column=0, row=4)
|
|
|
|
|
|
|
|
|
|
|
@ -94,9 +94,12 @@ lbl4.grid(column=0, row=6)
|
|
|
|
lbl5 = Label(root, text="", font=("Arial", 12))
|
|
|
|
lbl5 = Label(root, text="", font=("Arial", 12))
|
|
|
|
lbl5.grid(column=50, row=5)
|
|
|
|
lbl5.grid(column=50, row=5)
|
|
|
|
|
|
|
|
|
|
|
|
lblOut = Label(root, text="rtedgh", font=("Arial", 12))
|
|
|
|
|
|
|
|
lblOut.grid(column=0, row=7)
|
|
|
|
listOut = Listbox(root, selectmode='SINGLE', width=50)
|
|
|
|
|
|
|
|
listOut.grid(column=0, row=7, columnspan=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root.resizable(False, False)
|
|
|
|
root.resizable(False, False)
|
|
|
|
root.geometry('600x400')
|
|
|
|
root.geometry('325x400')
|
|
|
|
root.mainloop()
|
|
|
|
root.mainloop()
|
|
|
|