0

Hello all,

I normally lurk around and solve most of my issues by reading other threads. I have run into an issue and I am trying to figure out what I am missing. I am rather new at this so thanks for any advice.

What I am attempting to due is call to a module from my main program to access a Open Dialog window. The issue seems to be within my module that looks similar to:

def GetFile():
      from Tkinter import Tk
      import tkFileDialog


       toplevel = Tk()
       toplevel.withdraw()


        filename = tkFileDialog.askopenfilename()

I am calling GetFile from the command of a button. When i click the button it throws a NamerError at toplevel = Tk() saying that global name Tkinter is not defined.

I have no formal training on this so I am hoping I am making sense.

I am guessing I have syntax messed up and thing not in the right place, but it this the best way to go about calling a dialog box from a module?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Sync.Void
0

Reformulated program to function only without knowing specific use case:

import os
from Tkinter import Tk
import tkFileDialog

toplevel = Tk()
toplevel.withdraw()

filename = tkFileDialog.askopenfilename()

if os.path.isfile(filename):
    for line in open(filename,'r'):
        print line,
else: print 'No file chosen'

Edited by pyTony: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.