filedialog.askdirectory()的默认值是什么?

时间:2019-05-09 04:18:59

标签: python tkinter

我写了一些代码 制作GUI程序

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)

如果我关闭没有选择目录的文件浏览器(按esc或单击[x])

然后一个值将返回到dirName。

是什么?空值? 0?垃圾? 我如何获取该值并将其插入####?

感谢您阅读

1 个答案:

答案 0 :(得分:1)

您可以使用var down = false; // by default will be false $(document).mousedown(()=>{down = true;});// when mouse will be down it will make it true function checkDown() { return down;// returns the current status of down } 将目录设置为所需的目录:

initialdir

如果用户单击取消而不是单击确定,则返回的值为空。

如果要检查是否设置了值,只需执行以下操作:

dirName = filedialog.askdirectory(parent=root,
                                  initialdir="/path/to/start",
                                  title='Please select a directory')
相关问题