Help Needed !!! Browsing and Selecting More Than One File

Discussion in 'Python' started by Kilicaslan Fatih, Jul 6, 2006.

  1. Dear Diez B. Roggisch,

    After clicking a button on the GUI the user can browse
    and than select a ".c" file to assign to the other
    program I have mentioned.

    But in this way I can only select one file. I don't
    know how to implement this application for all of the
    "*.c" files in a folder. Do I need to write a for loop
    for this? Or maybe I can create a list after
    sequentially browsing files and than assign this list
    as a parameter to the function I am executing.

    Here is a part of the code, I am new to Python and
    OOP. Sorry for the ambiguity in my question.

    class App:

    #Browsing the file, this is triggered
    #through a menu
    def browseFile(self):
    global file
    file = askopenfilename(filetypes = [("C source
    code", "*.c"), ("All Files", "*.*")])

    #Running the CC program
    #This is triggered by a button push

    def runCC(self, event):

    if type(file)==str:
    dosya = file
    cmd = 'cc ' + dosya
    return os.system(cmd)
    else:
    message = tkMessageBox.showinfo("Window
    Text", "Please Browse a File Firstly")
    print message

    Regards,
    Fatih K.

    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
     
    Kilicaslan Fatih, Jul 6, 2006
    #1
    1. Advertisements

  2. Kilicaslan Fatih

    Eric Brunel Guest

    (Please quote at least a significant part of the message you're replying
    to, or people will have trouble understanding what you're talking about....)

    What has it to do with running your program with several file names as
    arguments? Is it two different ways to select several files in your
    application? Or do you want one or the other?
    This is unrelated to your question, but why do you use a global variable
    in a class? Can't you use an instance attribute, or a class attribute? And
    BTW, file is the name of a built-in, so using it to name a variable is a
    bad idea.
    So is it a third way of selecting multiple files? Anyway, if you want to
    be able to select multiple files via askopenfilename, use
    askopenfilename(..., multiple=1). The value returned by the function will
    then be a sequence of file names.
    Unrelated to your question again, but explicitely testing the type of a
    variable is usually a bad idea. What can be stored in file? I'd set it to
    None in the beginning, then test "if file is not None:" instead of testing
    its type.
    This line will always print None (or an empty string maybe), as
    tkMessageBox.showinfo doesn't return anything. No print is needed here, as
    showinfo already displays the message in a dialog.

    You also have a branch of the 'if' explicitely returning something (the
    result of the os.system call) and the other one not returning anything,
    i.e implicitely returning None. Is there a reason for that? This is -
    again - usually a bad idea as it makes your code difficult to understand..

    HTH
     
    Eric Brunel, Jul 6, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.