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?
1/9/2020 11:32:38 AMOlívia
4 AnswersNew Answer
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()).
If your code is object oriented programming, then make a local boolean variable of default = False, and in an if-else statement.. If(localvarible == False): function1() function2()
1. Why don't you wrap the two functions in one single function, and then use it ? def func(): function1() function2() 2. Your attempt ?
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.