2016-11-28 4 views
-1

私は、データを含むファイルを選択して要約結果を表示するために、GUIを使って凸包処理の3つの異なるアルゴリズムを実装する、Python言語でプログラムを作成する必要があります。GUI pythonファイルのインポート

GUI用にtkniterを使用していますが、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

あなたが質問をしていなかったが、コードを使用して、少なくとも3つの問題があります。 1.ローカル変数linesは、OpenFileが返されるとすぐに消えます。行をグローバル変数にして、それを宣言します。 2. label1label2の両方がNoneとなるため、戻り値はplaceです。 3. 2つのジオメトリ・マネージャを使用します。一つを選ぶ。 (私は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()