1 Feet = 0.3048 Meter
1 Meter = 3.2808 Feet
m1.bind("<FocusIn>",lambda x: m1.select_range(0,tk.END))
f1.bind("<FocusIn>",lambda x: f1.select_range(0,tk.END))
Here m1 is our Entry box to accept data in Meter and f1 is the Entry box to accept data in feet.
m1.bind("<FocusOut>",my_upd2)
f1.bind("<FocusOut>",my_upd1)
Inside the functions we used get() and set() methods of DoubleVar() to collect and update the data. After the conversion we used round() to restrict the output to 2 decimal places.
def my_upd1(*args): # data entered as feet
m1_var.set(round(f1_var.get()*0.3048,2))
Full code is here
import tkinter as tk
from tkinter import END
my_w = tk.Tk()
my_w.geometry("800x500") # Size of the window
my_w.title("www.plus2net.com") # Adding a title
font1=('Times',34,'normal') # font size
l1 = tk.Label(my_w, text='Meter', width=10,font=font1 ) # Label
l1.grid(row=0,column=0,padx=10,pady=10)
m1_var=tk.DoubleVar() # Double variable
m1 = tk.Entry(my_w,width=10,bg='yellow',font=font1,textvariable=m1_var)
m1.grid(row=0,column=1,padx=10)
l2 = tk.Label(my_w, text='Feet', width=10,font=font1 ) # Label
l2.grid(row=1,column=0,padx=10,pady=10)
f1_var=tk.DoubleVar()
f1 = tk.Entry(my_w,width=10,bg='yellow',font=font1,textvariable=f1_var)
f1.grid(row=1,column=1,padx=10)
# Layout is over #
def my_upd1(*args): # data entered as feet
m1_var.set(round(f1_var.get()*0.3048,2))
def my_upd2(*args): # data entered as meter
f1_var.set(round(m1_var.get()*3.2808,2))
m1.bind("<FocusOut>",my_upd2) # lost focus
f1.bind("<FocusOut>",my_upd1)
# Selection of all data on focus
m1.bind("<FocusIn>",lambda x: m1.select_range(0,tk.END))
f1.bind("<FocusIn>",lambda x: f1.select_range(0,tk.END))
my_w.mainloop() # Keep the window open
1 Feet = 0.3048 Meter
1 Meter = 3.2808 Feet
1 Kadi = 0.66 Feet
To our above code we will add one more input and integrate the same to get output in all units. User can add data in any one of the input Entry widget and on focus out, other two will show the equivalent values in respective units.
import tkinter as tk
from tkinter import END
my_w = tk.Tk()
my_w.geometry("800x500") # Size of the window
my_w.title("www.plus2net.com") # Adding a title
font1=('Times',34,'normal')
l1 = tk.Label(my_w, text='Meter', width=10,font=font1 ) # Label
l1.grid(row=0,column=0,padx=10,pady=10)
m1_var=tk.DoubleVar()
m1 = tk.Entry(my_w,width=10,bg='yellow',font=font1,textvariable=m1_var)
m1.grid(row=0,column=1,padx=10)
l2 = tk.Label(my_w, text='Feet', width=10,font=font1 ) # Label
l2.grid(row=1,column=0,padx=10,pady=10)
f1_var=tk.DoubleVar()
f1 = tk.Entry(my_w,width=10,bg='yellow',font=font1,textvariable=f1_var)
f1.grid(row=1,column=1,padx=10)
l3 = tk.Label(my_w, text='Kadi', width=10,font=font1 ) # Label
l3.grid(row=2,column=0,padx=10,pady=10)
k1_var=tk.DoubleVar()
k1 = tk.Entry(my_w,width=10,bg='yellow',font=font1,textvariable=k1_var) # text box
k1.grid(row=2,column=1,padx=10)
def my_upd1(*args): # feet is entered
in_meeter=round(f1_var.get()*0.3048,2)
m1_var.set(in_meeter)
k1_var.set(round(f1_var.get()*0.66,2))
def my_upd2(*args): # meeter is entered
in_feet=m1_var.get()*3.2808
f1_var.set(round(in_feet,2))
k1_var.set(round(in_feet/0.66,2))
def my_upd3(*args): # kadi is entered
in_feet=k1_var.get()*0.66
m1_var.set(round(in_feet*0.3048,2))
f1_var.set(round(in_feet,2))
f1.bind("<FocusOut>",my_upd1)
m1.bind("<FocusOut>",my_upd2)
k1.bind("<FocusOut>",my_upd3)
m1.bind("<FocusIn>",lambda x: m1.select_range(0,tk.END))
f1.bind("<FocusIn>",lambda x: f1.select_range(0,tk.END))
k1.bind("<FocusIn>",lambda x: k1.select_range(0,tk.END))
my_w.mainloop() # Keep the window open
Tkinter EntryShow Hide Password Using Checkbutton
Tkinter Text How to Validate user entered data
JavaScript Application to convert Feet to Meter and vice versa
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.