0

I was making an app i have tried everything but the error is not going. it's just a simple GUI but if you find any mistakes, please do tell me, I am still learning python and this is the first time using tkinter and need some help

   import tkinter as tk
 h=700
 w=700

def process():
 try:   
   I=entry.get(E1)
   R=entry.get(E2)
   v=entry.get(E3)
   V=v*R*I*0.5
   entry.insert(E4,V)
   print(V)

root=tk.Tk()

canvas=tk.Canvas(bg="#333333", height=h, width=w)        
canvas.pack()


frame=tk.Frame(root, bg='#4d4d4d')
frame.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.9)


label=tk.Label(frame, text="Calculator", bg='#8c8c8c', font='verdana 23')
label.place(relx=0.25, rely=0, relwidth=0.50, relheight=0.17)

L1=label=tk.Label(frame, text="Enter Current", bg='#8c8c8c', font="verdana 15")
L1.place(relx=0, rely=0.3, relwidth=0.40, relheight=0.10)

E1=entry=tk.Entry(frame, bg='#b3b3b3', font="Calibri 12")
E1.place(relx=0.45, rely=0.3, relwidth=0.40, relheight=0.10)

L2=label=tk.Label(frame, text="Enter Resistance", bg="#8c8c8c", font="verdana 15")
L2.place(relx=0, rely=0.5, relwidth=0.40, relheight=0.10)

E2=entry=tk.Entry(frame, bg='#b3b3b3', font='verdana 15')
E2.place(relx=0.45, rely=0.5, relwidth=0.40, relheight=0.10)

L3=label=tk.Label(frame, text='Enter Volume', bg='#8c8c8c', font='verdana 15')
L3.place(relx=0, rely=0.7, relwidth=0.40, relheight=0.10)

E3=entry=tk.Entry(frame, bg='#b3b3b3', font='verdana 15')
E3.place(relx=0.45, rely=0.7, relwidth=0.40, relheight=0.10)

button=tk.Button(root, text="Calculate", bg="#e6e6e6", command=process)
button.place(relx=0.15, rely=0.80, relwidth=0.40, relheight=0.1)

E4=tk.Entry(frame, bg="#b3b3b3", font='verdana 15')
E4.place(relx=0.30, rely=0.90, relwidth=0.40, relheight=0.10)

root.mainloop()
ajay gandhi
  • 577
  • 3
  • 13

1 Answers1

0

Problem is there is no except statement after try. If you don't want to handle exceptions you can do this:

 try:   
   I=entry.get(E1)
   R=entry.get(E2)
   v=entry.get(E3)
   V=v*R*I*0.5
   entry.insert(E4,V)
   print(V)
except:
   pass

root=tk.Tk()

it should work fine.

  • 1
    You're right about the missing `except` block, but using a catch-all `except` and ignoring exceptions are generally considered very bad practices. – Thierry Lathuille Apr 29 '20 at 06:34
  • 1
    the unexpected indent is now coming at "except: pass" – Hiiammister Apr 29 '20 at 06:36
  • 1
    @Hiiammister The indents in your code are completely messed up, with one space indents in some places... Please respect the Python convention of using 4 spaces for indent, that will make it all clearer. – Thierry Lathuille Apr 29 '20 at 06:39