0

So I'm able to run this perfectly fine through IDLE, but when I try to run it through the shell by double clicking, I get the following when I click the "Select Directory" button:

"NameError: name 'filedialog' is not defined"

I'm just getting the hang of tkinter, if you see anything else that would be coded a better way I'm open to criticism.

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()
Kyrubas
  • 877
  • 8
  • 23

1 Answers1

0

Use

from tkinter import filedialog

together with

from tkinter import *

(Though it's recommended to import Tkinter like this: )

import tkinter as tk
TidB
  • 1,749
  • 1
  • 12
  • 14