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 listmy_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()