Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from functools import partial
- # global variable
- val = "cm"
- val1 = "cm"
- # getting drop down value
- def store_l(sel_l):
- global val
- val = sel_l
- # getting drop down value
- def store_l1(sel_l):
- global val1
- val1 = sel_l
- # the main conversion
- def call_convert(rlabel1, rlabe12, inputn, inputn1):
- l = inputn.get()
- l1 = inputn1.get()
- if val == 'cm':
- m = float(l)+float(l1)
- i = float(l)-float(l1)
- rlabel1.config(text="%f add" % m)
- rlabe12.config(text="%f sub" % i)
- # if val == 'mm':
- # c = float(l+l1)/10
- # i = c*0.393701
- # rlabel1.config(text="%f cm" % c)
- # rlabe12.config(text="%f inches" % i)
- # if val == 'inches':
- # c = float(l+l1)/0.393701
- # m = c*10
- # rlabel1.config(text="%f cm" % c)
- # rlabe12.config(text="%f mm" % m)
- return
- # app window configuration and UI
- root = tk.Tk()
- root.geometry('400x250+100+200')
- root.title('Length Converter')
- root.resizable(width=False, height=False)
- root.grid_columnconfigure(1, weight=1)
- root.grid_rowconfigure(4, weight=1)
- numberInput = tk.StringVar()
- var = tk.StringVar()
- numberInput1 = tk.StringVar()
- var1 = tk.StringVar()
- # label and entry field
- input_label = tk.Label(root, text="Enter length1")
- input_entry = tk.Entry(root, textvariable=numberInput)
- input_label.grid(row=1)
- input_entry.grid(row=1, column=1)
- # label and entry field
- input_label = tk.Label(root, text="Enter length 2")
- input_entry = tk.Entry(root, textvariable=numberInput1)
- input_label.grid(row=2)
- input_entry.grid(row=2, column=1)
- # result label's for showing the other two tresults
- result_label1 = tk.Label(root)
- result_label1.grid(row=3, columnspan=4)
- result_label2 = tk.Label(root)
- result_label2.grid(row=4, columnspan=4)
- # drop down initalization and setup
- dropDownList = ["cm", "mm", "inches"]
- dropdown = tk.OptionMenu(root, var, *dropDownList, command=store_l)
- var.set(dropDownList[0])
- dropdown.grid(row=1, column=3)
- # drop down initalization and setup
- dropDownList = ["cm", "mm", "inches"]
- dropdown1 = tk.OptionMenu(root, var1, *dropDownList, command=store_l)
- var1.set(dropDownList[0])
- dropdown1.grid(row=2, column=3)
- # button click
- call_convert = partial(call_convert, result_label1, result_label2, numberInput, numberInput1)
- result_button = tk.Button(root, text="Convert", command=call_convert)
- result_button.grid(row=6, columnspan=4)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement