forked from Henry-Jia/python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_system_convertor.py
136 lines (117 loc) · 3.72 KB
/
number_system_convertor.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Number System convertor.
from tkinter import *
from tkinter import messagebox
def giver(str,l):
return int(str,l)
def inite():
d = val1.get()
p = str(el.get())
try:
if d=='Hexadecimal':
res = int(p,16)
if d=='Binary':
res = int(p,2)
if d=='Octal':
res = int(p,8)
if d=='Integer':
res = "same value"
res= str(res)
no = "RESULT : INTEGER FORMAT : "
no += res
no += " "*100
lbl = Label(text=no, bg='pink', fg='blue', font=for_font).place(x=200, y=500)
except:
messagebox.showinfo("Error","Some Error occurred")
def bine():
d = val1.get()
p = str(el.get())
try:
if d == 'Hexadecimal':
ip = giver(p,16)
res = str(bin(ip))
if d == 'Binary':
res = "lo same value"
if d == 'Octal':
ip = giver(p,8)
res = str(bin(ip))
if d == 'Integer':
res = str(bin(int(p)))
res = str(res[2:])
no = "RESULT : BINARY FORMAT : "
no += res
no += " " * 50
lbl = Label(text=no, bg='pink', fg='blue', font=for_font).place(x=200, y=500)
except:
messagebox.showinfo("Error", "Some Error occurred")
def octe():
d = val1.get()
p = str(el.get())
try:
if d == 'Hexadecimal':
ip = giver(p, 16)
res = str(oct(ip))
if d == 'Binary':
ip = giver(p,2)
res = str(oct(ip))
if d == 'Octal':
res = "lo same value"
if d == 'Integer':
res = str(oct(int(p)))
res = str(res[2:])
no = "RESULT : OCTAL FORMAT : "
no += res
no += " " * 100
lbl = Label(text=no, bg='pink', fg='blue',font=for_font).place(x=200, y=500)
except:
messagebox.showinfo("Error", "Some Error occurred")
def hexe():
d = val1.get()
p = str(el.get())
try:
if d == 'Hexadecimal':
res = "lo Same value"
if d == 'Binary':
ip = giver(p, 2)
res = str(hex(ip))
if d == 'Octal':
ip = giver(p,8)
res = str(hex(ip))
if d == 'Integer':
res = str(hex(int(p)))
res = str(res[2:])
no = "RESULT : HEXADECIMAL FORMAT : "
no += res
no += " " * 100
lbl = Label(text=no, bg='pink', fg='blue', font=for_font).place(x=200, y=500)
except:
messagebox.showinfo("Error", "Some Error occurred")
root = Tk()
root.title('Number system')
root.geometry('1360x768')
menubar = Menu(root)
root.config(menu=menubar)
filemenu = Menu(root, tearoff=0)
filemenu.add_command(label='New')
filemenu.add_command(label='Converter')
filemenu.add_separator()
filemenu.add_command(label='Exit', command=root.destroy)
menubar.add_cascade(label='File', menu=filemenu)
f = Frame(root, bg='pink', height=760, width=1360)
f.propagate(0)
f.pack()
for_font = ('Times', -40, 'bold')
el = Entry(f, width=30, bg='white', fg='blue', font=for_font)
el.place(x=500, y=50)
b1 = Button(f, text='Binary', font=for_font, bg='white', fg='blue', height=1, width=9, command=bine)
b1.place(x=100, y=200)
b2 = Button(f, text='Hexadecimal', font=for_font, bg='white', fg='blue', height=1, width=10, command=hexe)
b2.place(x=400, y=200)
b3 = Button(f, text='Octal', font=for_font, bg='white', fg='blue', height=1, width=9, command=octe)
b3.place(x=700, y=200)
b4 = Button(f, text='Integer', font=for_font, bg='white', fg='blue', height=1, width=9, command=inite)
b4.place(x=1000, y=200)
val1 = StringVar()
format = ('Hexadecimal', 'Binary', 'Octal', 'Integer')
s1 = Spinbox(f, textvariable=val1, values=format, font=for_font, width=15)
s1.place(x=100, y=50)
root.mainloop()