Advertisement
Felanpro

tkinter project

Sep 17th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. def get():
  4.     if len(e1.get()) == 0 or len(e2.get()) == 0:
  5.         errorL = Label(w, text = "Fill in the entries.", fg = "red")
  6.         errorL.grid(row = 2)
  7.     else:
  8.         pass
  9.        
  10.     firstNum = float(e1.get())
  11.     secondNum = float(e2.get())
  12.     answer = firstNum + secondNum
  13.     answerText = Label(w, text = answer, fg = "green")
  14.     answerText.grid(row = 3, column = 1, sticky = "w")
  15.  
  16. w = Tk()
  17. w.geometry("450x400")
  18. w.title("Application")
  19.  
  20. e1 = Entry(w)
  21. e2 = Entry(w)    
  22. b1 = Button(w, text="Add", command = get)
  23. t1 = Label(w, text="First number: ")
  24. t2 = Label(w, text="Second number: ")
  25. helpText = Label(w, text = "Answer: ")
  26.  
  27. t1.grid(row = 0, column = 0)
  28. e1.grid(row = 0, column = 1, sticky = "w")
  29. t2.grid(row = 0, column = 2)
  30. e2.grid(row = 0, column = 3)
  31. b1.grid(row = 1, column = 0, sticky = "w")
  32. helpText.grid(row = 3, sticky = "w")
  33.  
  34. w.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement