0

Tkinter and Files

I have a programme in tkinter that saves a user information in files and the user needs to insert their blood sugar levels and with those we have to make averages and compare values... I have some questions and I would really appreciate some help!!! Is it possible for a button in tkinter to answer to two function? I've been searching online but I can't understand how. Another question is how can a make a weekly average from values saved in files?

9th Jan 2020, 11:32 AM
Olívia
Olívia - avatar
3 ответов
+ 1
I don't know if it's possible for a button in tkinter to answer to two functions, but maybe you can call one function from another, so both can be run. When saving the information, you could save them on different lines, and start the daily number with "Daily: ", so that when you read from the file, you can separate the lines into a list and remove ones that don't begin with "Daily: ". You could then use lstrip() to remove "Daily: " and convert each number into a integer. Then you could find the average by dividing the sum of the list(using sum()) by the length of the list(using len()).
9th Jan 2020, 11:39 AM
Jianmin Chen
Jianmin Chen - avatar
+ 3
1. Why don't you wrap the two functions in one single function, and then use it ? def func(): function1() function2() 2. Your attempt ?
9th Jan 2020, 11:36 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
If you mean chaining the two functions, or at least executing them in sequence, you can call the second function at the end of the first, or you can make a third function that is linked to the button, which calls the other two. To analyse data, I suggest to use the pandas library that is exactly designed for this, it can read from files (csv or excel too) and do calculations, transformations and statistical analysis. Actually pandas also works on SoloLearn now.
9th Jan 2020, 11:40 AM
Tibor Santa
Tibor Santa - avatar