dimanche 29 mars 2020

Can I have a python tkinter button with an if/else statement in its function that performs different actions depending on file found?

I want a tkinter button to do one thing or another depending on what file the function finds in a specific directory.

Is it possible to do it with something like this sample code, or how could it be accomplished? (This code seems to ignore the "else" part of the function.)

def test():

    x = glob('C:/*file1.txt')[0]
    y = glob('C:/*file2.txt')[0]

    if x:
        #Do stuff

    else:
        #Do this stuff

tk.Button(root,
          text = "Test",
          command = test,
          fg="gray17",
          width = 15).pack()

Aucun commentaire:

Enregistrer un commentaire