GUI python文件导入

GUI python文件导入,python,list,tkinter,Python,List,Tkinter,我必须用python语言编写一个程序,用GUI实现三种不同的凸包计算算法,以选择包含数据的文件并显示摘要结果 我正在使用tkniter作为GUI,从pc导入数据文件并将数据保存在列表中时遇到问题。 这是我的密码 def OpenFile (): filename = filedialog.askopenfilename() lines = filename.readlines() filename.close() root = Tk() root.title('conv

我必须用python语言编写一个程序,用GUI实现三种不同的凸包计算算法,以选择包含数据的文件并显示摘要结果

我正在使用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()

您没有问任何问题,但代码至少有三个问题。1.当
OpenFile
返回时,局部变量
line
将立即消失。将行设置为全局变量,并将其声明为全局变量。2.
label1
label2
都将是
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()