Try this.
>>> import tkinter as tk
>>> print(tk.filedialog.__doc__)
File selection dialog classes.
Classes:
- FileDialog
- LoadFileDialog
- SaveFileDialog
This module also presents tk common file dialogues, it provides interfaces
to the native file dialogues available in Tk 4.2 and newer, and the
directory dialogue available in Tk 8.3 and newer.
These interfaces were written by Fredrik Lundh, May 1997.
# Give you a list of method under tk
>>>dir(tk)
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
if it worked, then I would believe you can import that module like any other in python. I do not use Tk but I use python.. That would be my limited knowledge..
Clueless86
Junior Poster in Training
76 posts since Jul 2009
Reputation Points: 10
Solved Threads: 1
You can try this.
Test script from Ene Uran.
# use Tkinter's file dialog window to get
# a file name with full path, you can also use
# this to get filenames for a console program
# askopenfilename() gives one selected filename
# with Python25 use ...
#import Tkinter as tk
#from tkFileDialog import askopenfilename
# with Python30 use ...
import tkinter as tk
from tkinter.filedialog import askopenfilename
root = tk.Tk()
# show askopenfilename dialog without the Tkinter window
root.withdraw()
# default is all file types
file_name = askopenfilename()
print(file_name)
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
With the advent of Python3 Tkinter has turned into a package called tkinter. I usually add a try/except to pick the right import:
# a simple Tkinter number guessing game
# shows how to create a window, an entry, a label, a button,
# a button mouse click response, and how to use a grid for layout
import random
try:
# for Python2
import Tkinter as tk
except ImportError:
# for Python3
import tkinter as tk
def click():
"""the mouse click command response"""
global rn
# get the number from the entry area
num = int(enter1.get())
# check it out
if num > rn:
label2['text'] = str(num) + " guessed too high!"
elif num < rn:
label2['text'] = str(num) + " guessed too low!"
else:
s1 = str(num) + " guessed correctly!"
s2 = "\n Let's start a new game!"
label2['text'] = s1 + s2
# pick a new random number
rn = random.randrange(1, 11)
enter1.delete(0, 2)
# create the window and give it a title
root = tk.Tk()
root.title("Heidi's Guess A Number Game")
# pick a random integer from 1 to 10
rn = random.randrange(1, 11)
# let the user know what is going on
label1 = tk.Label(root, text="Guess a number between 1 and 10 -->")
# layout this label in the specified row and column of the grid
# also pad with spaces along the x and y direction
label1.grid(row=1, column=1, padx=10, pady=10)
# this your input area
enter1 = tk.Entry(root, width=5, bg='yellow')
enter1.grid(row=1, column=2, padx=10)
# put the cursor into the entry field
enter1.focus()
# action button, right-click it to execute command
button1 = tk.Button(root, text=" Press to check the guess ",
command=click)
button1.grid(row=2, column=1, columnspan=2, padx=10, pady=10)
# the result displays here
label2 = tk.Label(root, text="", width=50)
label2.grid(row=3, column=1, columnspan=2, pady=10)
# start the mouse/keyboard event loop
root.mainloop()
Note: do not change the package directory names!!!!
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212