各位大佬小生有个疑问
我在使用tkinter设计GUI界面时候,需要导入一个文件。这个文件的路径将作为函数CommunityDetection的参数。
def communityDetection(inputpath,n): filepath = open(inputpath) # 获取社区划分 G = nx.read_gml(filepath) k = n sc_com = SpectralClustering.partition(G, k) # 谱聚类 print(sc_com)
导入文件的过程 def open_file(): filename = filedialog.askopenfilename(title='打开网络文件') entry_filename.insert('insert', filename) return filename # 设置button按钮接受功能 button_import = tk.Button(root, text="导入复杂网络",command=open_file).pack() # 设置entry entry_filename = tk.Entry(root, width=30, font=("宋体", 10, 'bold')) entry_filename.pack() filepath=entry_filename.get()
但是这个filepath并不是导入文件的文件路径,还要怎么把这个路径转换为python的变量呢??
求解 感激不尽