This is my code:
from tkinter import *
def ftm(feet):
return feet * 0.305
def mtf(meters):
return meters / 0.305
def convert(amount, func, result):
value = func(float(amount.get()))
result.set(round((value), 3))
def choose():
choice = lol.get()
if choice == "ft":
feet = StringVar()
meters = StringVar()
rest = Toplevel()
f3 = Frame(rest)
f3.grid(column=0, row=0, sticky=(N,W,E,S))
f3.columnconfigure(0, weight=1)
f3.rowconfigure(0, weight=1)
feet_entry = Entry(f3, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))
Label(f3, text="feet").grid(column=3, row=1, sticky=W)
Label(f3, text="is equal to").grid(column=1, row=2, sticky=E)
Label(f3, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
Label(f3, text="meters").grid(column=3, row=2, sticky=W)
Button(f3,
text="Calculate",
command=lambda a=feet_entry, f=ftm, r=meters: convert(a, f, r)
).grid(column=2, row=3, sticky=W)
elif choice == "m":
meters = StringVar()
feet = StringVar()
pepp = Toplevel()
f4 = Frame(pepp)
f4.grid(column=0, row=0, sticky=(N,W,E,S))
f4.columnconfigure(0, weight=1)
f4.rowconfigure(0, weight=1)
meter_entry = Entry(f4, width=7, textvariable=meters)
meter_entry.grid(column=2, row=1, sticky=(W, E))
Label(f4, text="meters").grid(column=3, row=1, sticky=W)
Label(f4, text="is equal to").grid(column=1, row=2, sticky=E)
Label(f4, textvariable=feet).grid(column=2, row=2, sticky=(W, E))
Label(f4, text="feet").grid(column=3, row=2, sticky=W)
Button(f4,
text="Calculate",
command=lambda a=meter_entry, f=mtf, r=feet: convert(a, f, r)
).grid(column=2, row=3, sticky=W)
else:
rino = Toplevel()
f5 = Frame(rino)
f5.grid(column=0, row=0, sticky=(N,W,E,S))
Label(f5, text="ERROR!").grid(column=1, row=1)
rip = Tk()
f2 = Frame(rip)
f2.grid(column=0, row=0, sticky=(N,W,E,S))
f2.columnconfigure(0, weight=1)
f2.rowconfigure(0, weight=1)
c1=Label(f2, text="feet to meter or meter to feet?")
c1.grid(row=0, column=0)
c2=Label(f2, text='type "ft" for feet to meter, type "m" for meter to feet')
c2.grid(row=1, column=0)
lol = StringVar()
choice=Entry(f2, width=7, textvariable=lol)
choice.grid(row=2, column=0)
b1=Button(f2, text="Confirm", command=choose)
b1.grid(row=3, column=0)
rip.mainloop()
I want to add background image for all these windows. How do I do it?