I have a TextInput widget that is suppose to display text within a .log file.
The python script looks like
logginfo = ObjectProperty()
with open('logtest.log', 'r') as file:
loginfo = file.read()
The kivy file looks like
TextInput:
id: logginfo
text: root.loginfo
The problem is, the log file is only read once and that is what is displayed.
How can I update loginfo
whenever the .log file changes? In other words, how can I get a live feed of the logtest.log file?
You will have to produce a method/function that will check for changes and load the file to update the textbox for you. There is no "automagic" way to do it.
I don't work with kivy directly, but most GUI frameworks seem to come with some sort of timer, or timeout object. Kivy doesn't seem to be any different in this case. A quick search revealed that Kivy has a "Clock" object. I found some docs here.
Most of the time these work on a timeout, so you define the Clock, tell it what function to run, whether it should repeat or not, and how frequently to time out. Each time the Clock times out, the function will be called. You can code the function to do whatever you like, in this case, check the file for changes.
I'd suggest making a hash of the file (something simple like md5) and storing the hash in a variable. Then, each time the clock times out, it can simply compare the files hash, to the hash you stored in ram, and if it's changed, you know you need to update the text box with the new contents of the file. If it doesn't you don't need to re-access the file for another timeout interval.
If you have specific questions on problems you encounter trying to work through the project please make new questions with specific issues, again showing your code at that point.