Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import tkinter as tk
  2. from functools import partial
  3.  
  4. # global variable
  5. val = "cm"
  6.  
  7. val1 = "cm"
  8.  
  9.  
  10. # getting drop down value
  11. def store_l(sel_l):
  12. global val
  13. val = sel_l
  14.  
  15. # getting drop down value
  16. def store_l1(sel_l):
  17. global val1
  18. val1 = sel_l
  19.  
  20.  
  21. # the main conversion
  22. def call_convert(rlabel1, rlabe12, inputn, inputn1):
  23. l = inputn.get()
  24. l1 = inputn1.get()
  25. if val == 'cm':
  26. m = float(l)+float(l1)
  27. i = float(l)-float(l1)
  28. rlabel1.config(text="%f add" % m)
  29. rlabe12.config(text="%f sub" % i)
  30. # if val == 'mm':
  31. # c = float(l+l1)/10
  32. # i = c*0.393701
  33. # rlabel1.config(text="%f cm" % c)
  34. # rlabe12.config(text="%f inches" % i)
  35. # if val == 'inches':
  36. # c = float(l+l1)/0.393701
  37. # m = c*10
  38. # rlabel1.config(text="%f cm" % c)
  39. # rlabe12.config(text="%f mm" % m)
  40. return
  41.  
  42.  
  43. # app window configuration and UI
  44. root = tk.Tk()
  45. root.geometry('400x250+100+200')
  46. root.title('Length Converter')
  47. root.resizable(width=False, height=False)
  48. root.grid_columnconfigure(1, weight=1)
  49. root.grid_rowconfigure(4, weight=1)
  50.  
  51. numberInput = tk.StringVar()
  52. var = tk.StringVar()
  53.  
  54. numberInput1 = tk.StringVar()
  55. var1 = tk.StringVar()
  56.  
  57. # label and entry field
  58. input_label = tk.Label(root, text="Enter length1")
  59. input_entry = tk.Entry(root, textvariable=numberInput)
  60. input_label.grid(row=1)
  61. input_entry.grid(row=1, column=1)
  62.  
  63. # label and entry field
  64. input_label = tk.Label(root, text="Enter length 2")
  65. input_entry = tk.Entry(root, textvariable=numberInput1)
  66. input_label.grid(row=2)
  67. input_entry.grid(row=2, column=1)
  68.  
  69. # result label's for showing the other two tresults
  70. result_label1 = tk.Label(root)
  71. result_label1.grid(row=3, columnspan=4)
  72. result_label2 = tk.Label(root)
  73. result_label2.grid(row=4, columnspan=4)
  74.  
  75. # drop down initalization and setup
  76. dropDownList = ["cm", "mm", "inches"]
  77. dropdown = tk.OptionMenu(root, var, *dropDownList, command=store_l)
  78. var.set(dropDownList[0])
  79. dropdown.grid(row=1, column=3)
  80.  
  81. # drop down initalization and setup
  82. dropDownList = ["cm", "mm", "inches"]
  83. dropdown1 = tk.OptionMenu(root, var1, *dropDownList, command=store_l)
  84. var1.set(dropDownList[0])
  85. dropdown1.grid(row=2, column=3)
  86.  
  87. # button click
  88. call_convert = partial(call_convert, result_label1, result_label2, numberInput, numberInput1)
  89. result_button = tk.Button(root, text="Convert", command=call_convert)
  90. result_button.grid(row=6, columnspan=4)
  91.  
  92. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement