Hello File.py

Lith lith.usenet at gmail.com
Fri Feb 18 03:17:01 EST 2005


Here's a simple script, where I want to use a GUI to select a file.
(And eventually do something interesting with it.) Some problems
appear.

(1) Why does it call MenuOpen automatically?

(2) Why won't it open when I choose the menu item?

(3) Python Cookbook gave me the sys.exit call, if I run it from IDLE it
gives me a traceback. Should I be using something else?

(4) Does tkFileDialog have any useful official documentation? The main
google results for it don't even give the possible parameters for the
function calls, or sample code showing how to use.

(5) Is the 'parent = parent,' line just plain wrong?

Feel free to note any horrors you see.


..........................

import sys
from Tkinter import *
import tkFileDialog

def MenuOpen(parent):
    tkFileDialog.askopenfilename(
        defaultextension    = '.ctb',
        filetypes           = [
            ('AutoCAD Color-Dependent Style Table Files', '*.ctb'),
            ('AutoCAD Named Style Table Files', '*.stb'),
            ('All Files', '*.*')
                              ],
        initialdir          = '\\\\Desktop',
        initialfile         = '',
        parent              = parent,
        title               = 'Open Plot Style File...'
    )


def DoInterface():
    root        = Tk()

    menubar     = Menu(root)
    root.config(menu = menubar)

    menuFile    = Menu(menubar)
    menuFile.add_command(   label='Open',
command=MenuOpen(parent=root))
    menuFile.add_separator()
    menuFile.add_command(   label='Exit', command=sys.exit)

    menubar.add_cascade(    label='File', menu=menuFile);

    root.mainloop()

#----------------------------------------------------------------

DoInterface()




More information about the Python-list mailing list