tkinter for show среднее арифметическое, среднеквадратичная погрешность in python

Here's an example code to create a tkinter GUI that shows the average and standard deviation of a list of numbers inputted by the user.

main.py
import tkinter as tk
from statistics import mean, stdev

class GUI(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        # create labels, entry boxes, and button
        tk.Label(self, text="Enter a list of numbers separated by spaces:").grid(row=0)
        self.num_entry = tk.Entry(self)
        self.num_entry.grid(row=0, column=1)

        tk.Button(self, text="Calculate", command=self.calculate).grid(row=1, column=0, columnspan=2)

        # create labels to display the results
        self.mean_label = tk.Label(self, text="")
        self.mean_label.grid(row=2, column=0)

        self.stdev_label = tk.Label(self, text="")
        self.stdev_label.grid(row=3, column=0)

    def calculate(self):
        # get the list of numbers from the entry box
        num_str = self.num_entry.get()
        num_list = num_str.split()

        # convert the strings to floats
        num_list = [float(num) for num in num_list]

        # calculate the mean and standard deviation
        mean_val = mean(num_list)
        stdev_val = stdev(num_list)

        # display the results
        self.mean_label.config(text="Mean: {:.2f}".format(mean_val))
        self.stdev_label.config(text="Standard Deviation: {:.2f}".format(stdev_val))

root = tk.Tk()
app = GUI(master=root)
app.mainloop()
1405 chars
44 lines

When the user clicks the "Calculate" button, the program gets the list of numbers from the entry box, converts the strings to floats, calculates the mean and standard deviation using the statistics module, and displays the results in labels. The mean is formatted to two decimal places and the standard deviation is also formatted to two decimal places.

gistlibby LogSnag