When I try to build a simple UI, everything works well, except the tkinter function I used always repeats twice, I am not sure why this happens and how to deal with it. Here is an example code:
import tkinter as tk
root = tk.Tk()
dirname = tk.filedialog.askdirectory(parent=root, initialdir="/",title='Please select a directory')
print(dirname)
When I run this code, the function works well, it will let me select a folder, but after I select the folder, it asks me to select it again. And from the print(), it outputs both the folders I have selected.
What should I do to make it only run one time?