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 
e1_str=tk.StringVar() # string variable 
e1 = tk.Entry(my_w, width=20,bg='yellow',font=font1,textvariable=e1_str)


# 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' )  

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

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    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 FORUM . Contact us
    ©2000-2023 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer