Is there a way to manually update Tkinter plots from another file?
I have another file that needs to be continuously polling (while True), so I believe I can't have a mainloop in the plots class since it would block my main class. Is there any way I can call the method "plot_data" from this other file and have the graphs (a,b,c,d) update live? Currently the frame freezes and live updates aren't seen.
However it seems to update in real time when the program is being run in debug mode. Is there a reason why the behavior in execution is different between RUN/ DEBUG in Pycharm?
Below is a view of the Plots class:
class Plots(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "GUI")
# TODO Make sure 'zoomed' state works on all laptops
self.state('zoomed') # Make fullscreen by default
container = tk.Frame(self, bg='blue')
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
frame = GraphPage(container)
self.page = GraphPage
frame.configure(background='black')
self.frame = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame() # Display frame on window
def show_frame(self):
frame = self.frame
frame.tkraise()
def plot_data(self):
# TODO Add exception handling for opening the file
file = open("../storage/data.csv", "r") # Open data file for plotting
t_list = ...
a_list = ...
v_list = ...
a2_list = ...
a.clear()
a.plot(time_list, t_list)
a.set_ylabel('T')
b.clear()
b.plot(time_list, a_list)
b.set_ylabel('A')
c.clear()
c.plot(time_list, v_list)
c.set_ylabel('V')
d.clear()
d.plot(time_list, a2_list)
d.set_xlabel('Time(s)')
d.set_ylabel('A')
class GraphPage(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
label = tk.Label(self, bg='red', text="GUI", font=LARGE_FONT, width=400)
label.pack(pady=10, padx=10)
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
The other file is essentially just:
while(true):
plots.plot_data()