Tkinter filedialog NameSpace错误

时间:2014-09-07 17:58:54

标签: python-3.x tkinter filedialog

所以我能够通过IDLE完美地运行它,但当我尝试通过双击运行它时,当我点击"选择目录"按钮:

" NameError:name' filedialog'未定义"

我只是掌握了tkinter,如果你看到其他任何可以编码的方式,我会受到批评。

from tkinter import *
import os, subprocess, shutil

window = Tk()
currentdir = StringVar()

def getdir():
    global currentdir
    currentdir.set(filedialog.askdirectory(initialdir = os.getcwd()))
def run():
    window.destroy()
seldirbtn = Button(window, text = "Select Directory", command = getdir)
seldirbtn.grid(row =0, column =0)

seldirlbl = Label(window, textvariable = currentdir)
seldirlbl.grid(row =0, column =2)

runbtn = Button(window, text = "RUN", command = run)
runbtn.grid(row = 1, column =1)

window.mainloop()

1 个答案:

答案 0 :(得分:0)

使用

from tkinter import filedialog

一起
from tkinter import *

(虽然建议像这样导入Tkinter:)

import tkinter as tk