(Linux) In the following program when the command python permissions.ph is issued I simply get another prompt, but when python3 permissions.py is issued I get the error below. Why does python2 see tkinter but python 3 doesn't?

garrett@bedroom ~/Projects/TestArea $ python permissions.py 
garrett@bedroom ~/Projects/TestArea $ python3 permissions.py 
Traceback (most recent call last):
  File "permissions.py", line 1, in <module>
    from Tkinter import *
ImportError: No module named 'Tkinter'
garrett@bedroom ~/Projects/TestArea $ 






from Tkinter import *
def fileopenbox(msg=None, title=None, default=None):
    root = Tk()
    root.withdraw()
    f = tkFileDialog.askopenfilename(parent=root,title=title, initialfile=default)
    if not f: return None
    return os.path.normpath(f)

Recommended Answers

try:
    # for Python2
    import Tkinter as tk
    import tkFileDialog as tkfd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.filedialog as tkfd
Jump to Post

All 4 Replies

Re: python3 and tkinter vs Tkinter 80 80

It is tkinter in Python3. http://docs.python.org/dev/library/tkinter.html

tkinter.filedialog
Common dialogs to allow the user to specify a file to open or save.

Re: python3 and tkinter vs Tkinter 80 80

But I set same error when I change the line from Tkinter import * to from tkinter import *

Re: python3 and tkinter vs Tkinter 80 80

And change to the tkinter.filedialog?

Re: python3 and tkinter vs Tkinter 80 80
try:
    # for Python2
    import Tkinter as tk
    import tkFileDialog as tkfd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.filedialog as tkfd
commented: good help +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.