I am using tkinter to create a visualization tool. This tool has an input panel which has a couple of different options such as a bar plot of births, a word cloud of names, etc. The goal of this project is to have a user click a visualization and have that visualization displayed in the middle of the GUI. After, they can click a different visualization and have that displayed instead in the same spot as the last visualization. This will allow the user to see many different visualizations, one by one, based on the data set that they uploaded.
I am currently using plt.savefig('foo.jpg', bbox_inches='tight')
to save an image to the directory after one of the options is chosen and the visualization is made. Then I use:
image = Image.open("foo.jpg")
photo = ImageTk.PhotoImage(image)
label_rhss = Label(image=photo)
to open the image into the label. Unfortunately, this never updates unless I close and reopen the application and then the new visualization is created in the desired place. But this is by no means a viable solution for any user, especially after adding many more visualization options.
Is there a way to make it that every time I create a visualization plot with tkinter, to have that visualization displayed in the middle panel. From my understanding, tkinter does not update when saving the picture to a file and then accessing that after. I have tried a couple of methods but none seems to work.
Will it be easier for me to change to a different GUI such as Spyder or maybe a method that can update every time I create a visualization and place it immediately in the desired label in tkinter since the saving method does not seem to work?
Edit: The code that I am using to create the visualizations is in the form of radio buttons such as
radiobutton4 = Radiobutton(
root,
bg = 'blue',
command = ShowWordCloud,
text = 'WordCloud of Names',
variable = v,
indicatoron = 0,
value = 3
)
The command in the radio button then calls the code which generates the word cloud and saves it as foo.jpg. I cant get this NEW foo.jpg to update as the new label image.
I hope this clarifies the problem a bit!