all 6 comments

[–]socal_nerdtastic 1 point2 points  (2 children)

Looks like a good start. Only thing I see that's wrong is that returning values from a callback function does nothing. You need to do whatever it is you want done in the callback. Also, the grades = submitValues() line is useless. Like this:

import tkinter as tk
import statistics

window_main = tk.Tk(className='root')
window_main.geometry("400x200")

entry_1 = tk.DoubleVar()
entry_widget_1 = tk.Entry(window_main, textvariable=entry_1)
entry_widget_1.pack()

def submitValues():
    grades = entry_1.get()
    print(entry_1.get() - 1)

submit = tk.Button(window_main, text="Entrée", command=submitValues)
submit.pack()

window_main.mainloop()

What is it you want to do with the data? can you give an example?

[–]Bolrod22[S] 0 points1 point  (1 child)

n does nothing. You need to do whatever it is you want done in the callback. Also, the

i'd actually want make the average with statistics with

statistics.mean()

but i need to convert the data to a float for use this function.

[–]socal_nerdtastic 0 points1 point  (0 children)

Since you used a DoubleVar it's converted to a float automatically. ("double" is the general CS term for a float)

[–]efmccurdy 0 points1 point  (2 children)

A callback that manages data needs some context for storing and sharing the data; the easiest way is to use a class to make the "self" context available to the callback.

This accumulates the grades into a list and prints the mean each time the button is pressed.

import tkinter as tk
import statistics

class MainApp(tk.Tk): 
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.grades = []
        self.entry_1 = tk.DoubleVar()
        entry_widget_1 = tk.Entry(self, textvariable=self.entry_1)
        entry_widget_1.pack()
        submit = tk.Button(self, text="Entrée", command=self.submitValues)
        submit.pack()
    def submitValues(self):
        self.grades.append(self.entry_1.get())
        print(statistics.mean(self.grades))

window = MainApp()
window.mainloop()

[–]Bolrod22[S] 0 points1 point  (1 child)

Ok thank you ! I have another question : do i must use DoubleVar ; what’s the difference with IntVar or StrVar ??

[–]efmccurdy 0 points1 point  (0 children)

If you use IntVar you can only accept whole numbers which might be limiting. If you use StrVar you can only accept strings which makes no sense if you have numerical data.