2016-11-28 89 views
-1

我必須用python語言編寫一個程序,該程序實現了三種不同的算法,用於使用GUI進行凸包計算,以選擇包含數據的文件並顯示彙總結果。GUI python文件導入

我使用tkniter的GUI,我有問題從PC導入數據文件並將數據保存在列表中。 這是我的代碼

def OpenFile(): 
    filename = filedialog.askopenfilename() 
    lines = filename.readlines() 
    filename.close() 

root = Tk() 
root.title('convex hull') 
root.geometry('400x300') 
label1 = ttk.Label(root,text="Enter points").place(x=20,y=3) 
label2 = ttk.Label(root,text = "Choose One of the algorithm to sort the points").place(x=0,y=60) 
btn1= ttk.Button(root,text="Browse", command = OpenFile) 
btn1.pack() 
+0

謝謝你它真的幫助 –

回答

0

你沒有問一個問題,但至少有三個問題的代碼。 1.當OpenFile返回時,局部變量lines消失。將行設爲全局變量並聲明它。 2. label1label2都將是None,因爲這是place的返回值。 3.您使用兩個幾何管理器。選一個。 (我推薦grid,但在這裏用pack。)

def OpenFile(): 
    global lines 
    filename = filedialog.askopenfilename() 
    lines = filename.readlines() 
    filename.close() 

root = Tk() 
root.title('convex hull') 
root.geometry('400x300') 
label1 = ttk.Label(root,text="Enter points") 
label1.pack() 
label2 = ttk.Label(root,text = "Choose One of the algorithm to sort the points") 
label2.pack() 
btn1= ttk.Button(root,text="Browse", command = OpenFile) 
btn1.pack()