I am using tkinter to write a simple GUI program to plot figure of some data, the plot function is realized using matplotlib module, here is my simplified code:
#!/usr/bin/env python
import Tkinter, tkFileDialog, tkMessageBox
from plot_core import berplot
class BerPlotTk(Tkinter.Frame):
def __init__ (self, master = None):
Tkinter.Frame.__init__(self, master, width = 500, height = 200)
self.fullfilenames = [] # filename with path
self.master = master
self.CreateWidgets()
def CreateWidgets(self):
# other widgets...
# Buttons
self.button_sel = Tkinter.Button(self, text = "Open", command = self.Open)
self.button_sel.grid(column = 0, row = 7, sticky = "EW")
self.button_plot = Tkinter.Button(self, text = "Plot", command = self.Plot)
self.button_plot.grid(column = 2, row = 7, sticky = "EW")
self.button_exit = Tkinter.Button(self, text = "Exit", command = self.top.quit)
self.button_exit.grid(column = 3, row = 7, sticky = "EW")
def Open(self):
input_filenames = tkFileDialog.askopenfilename(parent = self.master,
title = "Select the log file")
self.fullfilenames = list(self.tk.splitlist(input_filenames))
def Plot(self):
berplot(self.fullfilenames)
if __name__ == "__main__":
root = Tkinter.Tk()
app = BerPlotTk(root)
root.mainloop()
root.destroy()
berplot() is a function in another python module as:
from matplotlib.pyplot import *
def berplot(filelist):
# retrieve data x, y from the log file
# ...
ber = semilogy(x, y)
# ...
show()
return 1
The program can work, when I open the data file and click “Plot” button, it will create a figure window(by the matplotlib), but the GUI can not continue to process before I close the figure window. However, I want to continue to draw next figure while keeping current one, How can I realize this?
you can embed matplotlib figure in to Tk GUI:
http://matplotlib.sourceforge.net/examples/user_interfaces/index.html