2016-11-28 86 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()