I need some help
I have ben trying to make a calculator program in python and I did pretty good.
I wanted to use the same code and the Tkinter library to make a window for it but it has me so confused.
my calculator code is:
while True:
num1 = 0
num2 = 0
num3 = 0
print("Enter your calculation:")
calc_in = str(input()).split()
try:
num1 = int(calc_in[0])
op1 = calc_in[1]
num2 = int(calc_in[2])
except:
print("Error: Make sure you typed your sum correctly")
continue
try:
op2 = calc_in[3]
num3 = int(calc_in[4])
except:
pass
if op1 == "+":
answer = num1 + num2
elif op1 == "-":
answer = num1 - num2
elif op1 == "*":
answer = num1 * num2
elif op1 == "/":
answer = num1 / num2
try:
if op2 == "+":
answer = answer + num3
elif op2 == "-":
answer = answer - num3
elif op2 == "*":
answer = answer * num3
elif op2 == "/":
answer = answer / num3
except:
pass
print(answer)
And the code works ok but when I tried to use an entry widget for tinker it game me some weird thing back.
this is the code with Tkinter so far (i don't have the tkinter output bit yet cause i wanted to see if it would actually work):
import tkinter as tk
import tkinter.ttk as ttk
window = tk.Tk()
label = tk.Label(
text="Calculator",
foreground="white",
background="dodgerBlue",
width=15,
height=0,
font=("Arial", 25),
)
label.pack()
calc_input = tk.Entry(
foreground="dodgerBlue",
background="white",
width=15,
font=("Arial", 25),
)
calc_input.pack()
window.mainloop()
while True:
num1 = 0
num2 = 0
num3 = 0
convert = str(calc_input.get)
calc_in = convert.split()
print(calc_in)
break
try:
num1 = int(calc_in[0])
op1 = calc_in[1]
num2 = int(calc_in[2])
except:
print("Error: Make sure you typed your sum correctly")
continue
try:
op2 = calc_in[3]
num3 = int(calc_in[4])
except:
pass
if op1 == "+":
answer = num1 + num2
elif op1 == "-":
answer = num1 - num2
elif op1 == "*":
answer = num1 * num2
elif op1 == "/":
answer = num1 / num2
try:
if op2 == "+":
answer = answer + num3
elif op2 == "-":
answer = answer - num3
elif op2 == "*":
answer = answer * num3
elif op2 == "/":
answer = answer / num3
except:
pass
print(answer)
When I click enter nothing happens but when I close the window I get a weird array:
['<bound', 'method', 'Entry.get', 'of', '<tkinter.Entry', 'object', '.!entry>>']
I don't understand what is happening so any help would be greatly appreciated.