Average , Sum of user inputs

Average value of user inputs

We will read the user inputs by using get() meothod of StringVar() e1_str. By using split() we will create a list by passing all the elements through a built in function int() by using map() to convert them to integer. Using this value we will create one list my_list.

my_list= list(map(int,e1_str.get().split(','))) # List of elements
By using len() we will get Number of elements in the list.
By using sum() we will get sum of all the elements in the list.
By using config() we will update the text option to show the outputs.

Calculate sum, mean , Number of elements from user input in a Tkkinter window
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("550x250")  # width x heiht 
my_w.title("plus2net.com")  # Adding a title
font1=['Times',22,'normal'] # Higher font style
font2=['Times',16,'normal'] # font style 

lb1 = tk.Label(my_w,  text='Numbers',font=font1 )  # added one Label 
lb1.grid(row=1,column=1) 
e1_str=tk.StringVar() # string variable 
e1 = tk.Entry(my_w, width=20,bg='yellow',font=font1,textvariable=e1_str)
e1.grid(row=1,column=2) 

b1=tk.Button(my_w,text='Submit',font=font1,command=lambda:my_upd())
b1.grid(row=1,column=3,padx=5,pady=10)

# Single lable showing multiple lines 
lb2 = tk.Label(my_w,  text='Welcome \n 2nd line \n third', height=4,
        font=font2,anchor='w',justify='left',width=40,bg='lightgreen' )  
lb2.grid(row=2,column=1,padx=10,columnspan=3,sticky='w')

def my_upd():
    my_list= list(map(int,e1_str.get().split(','))) # List of elements
    str1=" No. of Elements : " + str(len(my_list))
    str1=str1 + "\n Sum of elements: " +str(sum(my_list))
    str1=str1 + "\n Average : " +str(sum(my_list)/len(my_list))
    lb2.config(text=str1) # Update the text option 
my_w.mainloop()
Tkinter Entry Show Hide Password Using Checkbutton Tkinter Text How to Validate user entered data JavaScript Application to convert Feet to Meter and vice versa
Projects in Tkinter Mean , sum and number of elemetns based on user inputs

Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate 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.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer