'Tkinter object-oriented file dialog?
The following code displays a file dialog, returning a file_path string that I may then use to, for example, import a csv directly into a pandas dataframe.
utilities.py:
import tkinter as tk
from tkinter import filedialog as fd
class FileDialog(tk.Tk): # inherits from the tk.Tk class
def __init__(self):
super().__init__()
self.withdraw() # prevents Tkinter window from displaying
def open(self):
return fd.askopenfilename()
def saveas(self):
return fd.asksaveasfilename()
main.py:
import utilities as util
file_path = util.FileDialog().open()
I am teaching myself advanced programming concepts such as inheritance and the self keyword, and am requesting feedback on whether I am applying these ideas correctly. Thank you for your time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
