-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogconv.py
68 lines (51 loc) · 2.19 KB
/
progconv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Programmers Calculator Script
from tkinter import *
from arithmetic import *
import tkinter as tk
def systemConverter():
class App:
def __init__(self, master):
self.menubar = tk.Menu(master)
master.config(menu=self.menubar)
self.entry = tk.Entry(master)
self.lstbx1 = tk.Listbox(master, selectmode=tk.BROWSE, exportselection=0)
self.lstbx2 = tk.Listbox(master, selectmode=tk.BROWSE, exportselection=0)
for i in ["Binary", "Octal", "Decimal", "Hexadecimal"]:
self.lstbx1.insert(tk.END, i)
self.lstbx2.insert(tk.END, i)
self.result = tk.Label(master, text="0")
self.error = tk.Label(master, text="")
#self.credits = tk.Label(master, text="Copyright whatever idc")
self.quit_button = tk.Button(master, text="Quit", fg="red",
command=master.quit)
self.submit_button = tk.Button(master, text="Submit", command=self.submit)
self.layout()
def layout(self):
self.lstbx1.grid(row=0, column=0)
self.lstbx2.grid(row=0, column=1)
self.entry.grid(row=1, column=0)
self.result.grid(row=1, column=1)
self.submit_button.grid(row=2, column=0)
self.quit_button.grid(row=2, column=1)
#self.credits.grid(row=3, column=0)
self.error.grid(row=3, column=1)
def submit(self):
try:
tmp = self.entry.get()
calc_src = self.lstbx1.curselection()
calc_dst = self.lstbx2.curselection()
src = {0: 2, 1: 8, 2: 10, 3: 16}
tmp = int(tmp, src[calc_src[0]])
dst = {0: bin, 1: oct, 2: int, 3: hex}
tmp = dst[calc_dst[0]](tmp)
self.error.configure(text="")
self.result.configure(text=tmp)
except ValueError:
self.error.configure(text="ERR")
print("Error, cannot convert the specified input")
root = tk.Tk()
app = App(root)
root.mainloop()
#root.destroy()
if __name__ == "__main__":
systemConverter()