Reputation: 41
i wrote some code to make GUI program
import os
from tkinter import *
from tkinter import filedialog
dirName = os.getcwd()
def getDirName():
global dirName
dirName = filedialog.askdirectory()
if dirName != ####:
lbl_1_2.configure(text=dirName)
else:
pass
# lbl_1_2 = Label(app, text=dirName)
# btn_1 = Button(app, text="change", width=15, command=getDirName)
If I close file explorer without select directory (press esc or click [x])
then a value will return to dirName.
what is it? null? 0? trash? how can I get that value and insert to #### ?
thank you for reading
Upvotes: 3
Views: 4832
Reputation: 47159
You set the directory to whatever you want with initialdir
:
dirName = filedialog.askdirectory(parent=root,
initialdir="/path/to/start",
title='Please select a directory')
If the user clicks cancel instead of OK then the value returned is empty.
If you want to check if a value is set simply do:
if dirName:
....
Upvotes: 7