我有下面的代碼,它使用Tkinter的askopenfilename來啓用用戶選擇文件。這個文件的內容然後用於圖形。我只使用Tkinter來允許用戶選擇文件,沒有別的。因此,在打開文件後,是否有Python腳本會結束Tkinter,我希望它位於標有'##'的行中。因爲Tkinter仍在運行,當它不需要時。我的代碼所用的代碼程序是在繪製圖形時停止。這裏是我的代碼:停止Tkinter的Python腳本
Exampe of the data
x,y,
1,4,
3,9,
6,7,
,,
#Code starts
import numpy as np
from Tkinter import Tk
from tkFileDialog import askopenfilename
import matplotlib.pyplot as plt
Tk().withdraw() # keep the root window from appearing (dont want full Gui)
filename = askopenfilename()# show an "Open" dialog box and return the path to the selected file print(filename)
data = np.genfromtxt(filename, dtype=[('x',float),('y',float)],comments='"', delimiter=',',skip_header=1,missing_values=True)
##Location of tkinter stop code##
x=data['x']
x = x[np.logical_not(np.isnan(x))] #Remove Nan values
y=data['y']
y = y[np.logical_not(np.isnan(y))] # Remove Nan values
plt.plot(x, y, 'ko', ms=4)
plt.show()
#Code Ends
感謝那些曾摧毀它 – Jay 2012-08-09 16:11:36