0
我正在使用tkinter編寫一個簡單的GUI程序來繪製一些數據的圖形,plot函數是使用matplotlib模塊實現的,這裏是我的簡化代碼:讓Tkinter繼續處理下一個事件,不關閉當前彈出窗口
#!/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()是另一個Python模塊的功能:
from matplotlib.pyplot import *
def berplot(filelist):
# retrieve data x, y from the log file
# ...
ber = semilogy(x, y)
# ...
show()
return 1
該程序可以正常工作,當我打開數據文件,然後單擊「繪圖」按鈕,它會創建一個圖形窗口(通過matplotlib),但是在關閉圖形w之前GUI不能繼續處理indow。但是,我想繼續在保持當前狀態的情況下繪製下一個圖形,我怎麼能意識到這一點?
謝謝,我用你的方法解決了這個問題。 – platinor