2020-08-06

又来写GUI了。

这次是一个更为复杂的。

刚开始就遇到了一个问题。

def openfile():
    #writeDirectory = tkFileDialog.askdirectory()
    #return writeDirectory
    tkinter.filedialog.askopenfilename()
def GUI():
    root = tk.Tk()
    root.title('Tester Troubleshooter')
    wintrace_location = tk.Button(root, text = 'Please Select Wintrace file Location', command = openfile(), height = 2).pack()
    """wintrace_location.grid(row = 0, sticky = 'NWE', columnspan = 2, padx = 2, pady = 2)
    wintrace_location.config(text = select_write_directory().replace('/', '\\') + '\\')
    cur_location = tk.Button(root, text = 'Please Select Wintrace file Location', command = select_write_directory(), height = 2)
    cur_location.grid(row = 1, sticky = 'NWE', columnspan = 2, padx = 2, pady = 2)
    cur_location.config(text=select_write_directory().replace('/', '\\') + '\\')"""
    root.mainloop()

GUI()

写了一个button,点了这个button要去选择文件位置。结果!!!每次运行还没点击button就已经弹出来让你选择位置的界面!搞了半天发现竟然是因为!!!openfile()后面的括号,去掉括号就好了。我哭了。。。

你可能感兴趣的:(python)