Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1.  
  2. from tkinter import *
  3. main = Tk()
  4. main.geometry("360x120")
  5.  
  6. #Function
  7.  
  8. def test():
  9. if variablecm.get() == OPTIONS1[0]:
  10. cm = int(num1.get()) * 10
  11. return cm
  12. if variablecm.get() == OPTIONS1[1]:
  13. cm = int(num1.get()) * 2.54
  14. return cm
  15. if variablecm.get() == OPTIONS1[2]:
  16. cm = int(num1.get()) / 10
  17. return cm
  18.  
  19.  
  20.  
  21. def test1 ():
  22. if variable.get() == OPTIONS2[0]:
  23. ans = int(test()) / 10
  24. num2.delete(0, END)
  25. num2.insert(0, ans)
  26. if variable.get() == OPTIONS2[1]:
  27. ans = int(test()) / 2.54
  28. num2.delete(0, END)
  29. num2.insert(0, ans)
  30. if variable.get() == OPTIONS2[2]:
  31. ans = int(test()) * 10
  32. num2.delete(0, END)
  33. num2.insert(0, ans)
  34.  
  35.  
  36.  
  37. #Entry
  38. num1 = Entry(main)
  39. num1.grid(row=0, column=0)
  40.  
  41. num2 = Entry(main)
  42. num2.grid(row=1, column=0)
  43.  
  44. #options
  45.  
  46. OPTIONS1 = [
  47. "decimeter",
  48. "inches",
  49. "millimeter",
  50. ]
  51.  
  52.  
  53. OPTIONS2 = [
  54. "decimeter",
  55. "inches",
  56. "millimeter",
  57. ]
  58.  
  59. #Variable
  60. variable = StringVar(main)
  61. variable.set(OPTIONS2[0])
  62.  
  63. variablecm = StringVar(main)
  64. variablecm.set(OPTIONS1[0])
  65.  
  66.  
  67. w2 = OptionMenu(main, variablecm, OPTIONS1[0], OPTIONS1[1], OPTIONS1[2])
  68. w2.grid(row=0, column=1)
  69.  
  70. w1 = OptionMenu(main, variable, OPTIONS2[0], OPTIONS2[1], OPTIONS2[2])
  71. w1.grid(row=1, column=1)
  72.  
  73.  
  74. #Button
  75. Button(text="Calculate", command=test1).grid(row=3, column=1)
  76.  
  77.  
  78. main.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement