Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. def kg_to_pounds_ounces_grams(kilogram):
  2. pound = kilogram * 2.20462
  3. oounce = kilogram * 35.274
  4. gram = kilogram * 1000
  5. return [pound, oounce, gram]
  6.  
  7. for textWidget,weight in zip(output, kg_to_pounds_ounces_grams(kg) ):
  8. textWidget.delete(1.0, END)
  9. textWidget.insert(END,weight)
  10.  
  11. from tkinter import *
  12.  
  13. window = Tk()
  14.  
  15.  
  16. def kg_to_pounds_ounces_grams(kilogram):
  17. pound = kilogram * 2.20462
  18. ounce = kilogram * 35.274
  19. gram = kilogram * 1000
  20. return [pound, ounce, gram]
  21.  
  22.  
  23. def convert_button_pressed():
  24. try:
  25. kg = float(e1_text.get())
  26. except:
  27. kg = float("NaN")
  28. map(lambda x: x.delete(1.0, END), output)
  29. # Missing Code goes here!
  30.  
  31.  
  32. l1 = Label(window, text="Kg")
  33. l1.grid(row=0, column=0)
  34.  
  35. e1_text = StringVar()
  36. e1 = Entry(window, textvariable=e1_text)
  37. e1.grid(row=0, column=1)
  38.  
  39. b1 = Button(window, text="Convert", command=convert_button_pressed)
  40. b1.grid(row=0, column=2)
  41.  
  42. t1 = Text(window, height=1, width=20)
  43. t1.grid(row=1, column=0)
  44.  
  45. t2 = Text(window, height=1, width=20)
  46. t2.grid(row=1, column=1)
  47.  
  48. t3 = Text(window, height=1, width=20)
  49. t3.grid(row=1, column=2)
  50.  
  51. output = [t1, t2, t3]
  52.  
  53. window.mainloop()
  54.  
  55. [x.delete(1.0, END) for xin output]
  56.  
  57. [x.insert(END, w) for x, w in zip(output, kg_to_pound_ounces_grams(kg))]
  58.  
  59. [(x.delete(1.0, END), x.insert(END, w)) for x, w in zip(output, kg_to_pound_ounces_grams(kg))]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement