Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bug in code
#1
I get the error "NameError: name 'tkFileDialog' is not defined" in the following code.
If anybody can tell me why, it would be greatly appreciated.


from tkinter import filedialog
from tkinter import *

def get_file1():
	print("Geting file 1\n")
	file1 =  tkFileDialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
	e1.insert(10,file1)

mw = Tk()
mw.geometry('350x200+400+200')
mw.title("Test Program")

w1 = Label(mw, text="Input File: ",font=("Arial Bold",12)).grid(row=0)
e1 = Entry(mw)
e1.insert(10, "infile.txt")
e1.grid(row=0,column=1)
Button(mw,text='Search',command=get_file1).grid(row=0, 
                                                       column=2, 
                                                       sticky=W, 
                                                       pady=4)

mw.mainloop()
Reply
#2
it should be filedialog (what you import on line 1), not tkFileDialog

You are using python 3, tkFileDialog is/was python2
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020