Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- main = Tk()
- main.geometry("360x120")
- #Function
- def test():
- if variablecm.get() == OPTIONS1[0]:
- cm = int(num1.get()) * 10
- return cm
- if variablecm.get() == OPTIONS1[1]:
- cm = int(num1.get()) * 2.54
- return cm
- if variablecm.get() == OPTIONS1[2]:
- cm = int(num1.get()) / 10
- return cm
- def test1 ():
- if variable.get() == OPTIONS2[0]:
- ans = int(test()) / 10
- num2.delete(0, END)
- num2.insert(0, ans)
- if variable.get() == OPTIONS2[1]:
- ans = int(test()) / 2.54
- num2.delete(0, END)
- num2.insert(0, ans)
- if variable.get() == OPTIONS2[2]:
- ans = int(test()) * 10
- num2.delete(0, END)
- num2.insert(0, ans)
- #Entry
- num1 = Entry(main)
- num1.grid(row=0, column=0)
- num2 = Entry(main)
- num2.grid(row=1, column=0)
- #options
- OPTIONS1 = [
- "decimeter",
- "inches",
- "millimeter",
- ]
- OPTIONS2 = [
- "decimeter",
- "inches",
- "millimeter",
- ]
- #Variable
- variable = StringVar(main)
- variable.set(OPTIONS2[0])
- variablecm = StringVar(main)
- variablecm.set(OPTIONS1[0])
- w2 = OptionMenu(main, variablecm, OPTIONS1[0], OPTIONS1[1], OPTIONS1[2])
- w2.grid(row=0, column=1)
- w1 = OptionMenu(main, variable, OPTIONS2[0], OPTIONS2[1], OPTIONS2[2])
- w1.grid(row=1, column=1)
- #Button
- Button(text="Calculate", command=test1).grid(row=3, column=1)
- main.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement