I have created file dialog window with tkinter and two different functions: one works with images, another with videos. How can I make tkinter button to call different functions when either of filetypes passed into file dialog.
Asked
Active
Viewed 40 times
0
-
4Make a function that checks the filetype and calls one or the other accordingly. Attach that to button. – matszwecja Aug 22 '22 at 08:28
-
Could you please show me how to make that function? – Nighttwinkle Aug 22 '22 at 08:43
-
check the file extension. You can do this with the `os` standard library. See [this answer](https://stackoverflow.com/a/541394/9267296) for reference – Edo Akse Aug 22 '22 at 08:53
1 Answers
2
You can simply write a function that will check the extension and act accordigly:
def fun(filename):
if filename.endswith(".txt"):
fun_txt(filename)
else:
fun_doc(filename)

matszwecja
- 6,357
- 2
- 10
- 17