The people who are familiar with React and Flutter would easily understand this.
But for others, here's the explanation:
- When ever I change something in my python file which contains tkinter code, the change should be reflected in the main window (the main window should not re-open to reflect the changes).
I have tried to search on web as well as on stack over flow, but all the results are for updating value in entry, label, buttons etc. But what I want is, the whole window should be updated when ever I change something in my main file, and the main window should not be reopened to do so. So in short, updating whole window without closing it, on every changes in the main file or automatically reload your program on save without reopening!
What have I tried?:
- I tried to detect change in file using
os.getsize
which satisfied the first part of my question, but however I am not able to solve the second part i.e window should not be closed.
import os
main__tkinter_filename="myfile.py"
initial_filesize=os.path.getsize(main_tkinter_filename) # Getting size of the file for
# comparison.
while 1:
final_filesize=os.path.getsize(main_tkinter_filename)
if final_filsize<intial_filesize or final_filesize>initial_filesize:
webbrowser.open(main_tkinter_filename)
Example:
from tkinter import *
root=Tk()
root.mainloop
If i have added a=Label(text='text')
anda.pack()
after root=Tk()
, it should show me the label, and if i have removed the same code, it should remove them.
EDIT: I have invested a lot of time into this problem initially and have gained a significant, effective but highly complicated way to solve this problem. here's the repo.
Note: the code in repo is not in working state and would most probably never be in working state. The repo contains my idea to solve this problem as well as my work towards implementing the idea.