diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2025-12-21 16:51:31 +0000 |
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2025-12-21 16:51:31 +0000 |
| commit | 33291657255a3c6d57e1cdc269e545a10a6c78c3 (patch) | |
| tree | 87144d3c344a5e411a283688988a58e028669ad5 | |
| parent | 611ae94d709e343af6fa020643732268b8d67229 (diff) | |
| download | tkFileBrowser-33291657255a3c6d57e1cdc269e545a10a6c78c3.tar.gz tkFileBrowser-33291657255a3c6d57e1cdc269e545a10a6c78c3.zip | |
Made into a module, updated
| -rw-r--r-- | __init__.py | 1 | ||||
| -rw-r--r-- | fileTester.py | 25 | ||||
| -rw-r--r-- | fileTreeBrowser.py (renamed from tkFileBrowser.py) | 12 | ||||
| -rw-r--r-- | windowsIcons.py (renamed from winIcon.py) | 2 |
4 files changed, 9 insertions, 31 deletions
diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..a331161 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .fileTreeBrowser import TkFileBrowser
\ No newline at end of file diff --git a/fileTester.py b/fileTester.py deleted file mode 100644 index 65a2f2d..0000000 --- a/fileTester.py +++ /dev/null @@ -1,25 +0,0 @@ -import tkinter as tk -from tkinter import ttk -import os - -def on_close(): - if os.path.exists(os.path.join("E:", "temp")): - os.rmdir(os.path.join("E:", "temp")) - if os.path.exists(os.path.join(os.path.expanduser("~"), "temp")): - os.rmdir(os.path.join(os.path.expanduser("~"), "temp")) - - root.destroy() - -root = tk.Tk() -root.title("File tester program") -root.resizable(False, False) -root.protocol("WM_DELETE_WINDOW", on_close) - -tk.Label(root, text = "File tester program", font = ("Verdana", 16, "bold")).grid(row = 0, column = 0, columnspan = 2, padx = 3, pady = 3) - -ttk.Button(root, text = "Add in user", command = lambda: os.mkdir(os.path.join(os.path.expanduser("~"), "temp"))).grid(row = 1, column = 0, padx = 3, pady = 3, ipady = 3, ipadx = 3) -ttk.Button(root, text = "Delete in user", command = lambda: os.rmdir(os.path.join(os.path.expanduser("~"), "temp"))).grid(row = 1, column = 1, padx = 3, pady = 3, ipady = 3, ipadx = 3) -ttk.Button(root, text = "Add in E:\\", command = lambda: os.mkdir(os.path.join("E:", "temp"))).grid(row = 2, column = 0, padx = 3, pady = 3, ipady = 3, ipadx = 3) -ttk.Button(root, text = "Delete in E:\\", command = lambda: os.rmdir(os.path.join("E:", "temp"))).grid(row = 2, column = 1, padx = 3, pady = 3, ipady = 3, ipadx = 3) - -root.mainloop()
\ No newline at end of file diff --git a/tkFileBrowser.py b/fileTreeBrowser.py index 0a32cb4..162c981 100644 --- a/tkFileBrowser.py +++ b/fileTreeBrowser.py @@ -5,9 +5,10 @@ from tkinter import ttk from tkinter import messagebox from PIL import Image, ImageTk import win32api -import winIcon import os +from . import windowsIcons + MENU_DELETE = "menu_delete" MENU_OPEN = "open" MENU_CLIPBOARD = "clipboard" @@ -41,8 +42,8 @@ class TkFileBrowser(tk.Frame): self._types = types self._showhidden = showhidden - self._img_clipboard = tk.PhotoImage(file = os.path.join("Assets", "clipboard.png")) - self._img_cross = tk.PhotoImage(file = os.path.join("Assets", "cross.png")) + self._img_clipboard = tk.PhotoImage(file = os.path.join(os.path.dirname(__file__), "Assets", "clipboard.png")) + self._img_cross = tk.PhotoImage(file = os.path.join(os.path.dirname(__file__), "Assets", "cross.png")) self._book = DriveBook(self) self._book.pack(fill = tk.BOTH, expand = True) @@ -222,7 +223,7 @@ class TkFileBrowser(tk.Frame): #https://stackoverflow.com/questions/21070423/python-sAaving-accessing-file-extension-icons-and-using-them-in-a-tkinter-progra/52957794#52957794 #https://aecomputervision.blogspot.com/2018/10/getting-icon-association-for-any-file.html - return winIcon.get_icon(PATH, winIcon.SMALL) + return windowsIcons.get_icon(PATH, windowsIcons.SMALL) class DriveBook(ttk.Notebook): @@ -537,11 +538,12 @@ class RightClickMenu(tk.Menu): def on_click(path): print("click: ", path) +# to debug, `python -m tkFileBrowser.fileTreeBrowser` from parent directory if __name__ == "__main__": root = tk.Tk() browser = TkFileBrowser(root, command = on_click) browser.pack(side = tk.LEFT) - ttk.Button(root, text = "Goto", command = lambda: browser.see(r"F:\Python Projects\tkFileBrowser")).pack(side = tk.LEFT) + ttk.Button(root, text = "Goto", command = lambda: browser.see(r"C:\Users\eden\Pictures")).pack(side = tk.LEFT) root.mainloop()
\ No newline at end of file diff --git a/winIcon.py b/windowsIcons.py index 2a40a05..6c614c5 100644 --- a/winIcon.py +++ b/windowsIcons.py @@ -45,7 +45,7 @@ def get_icon(PATH, size): return if size == "small": - img = img.resize((16, 16), Image.ANTIALIAS) + img = img.resize((16, 16)) return img class WinIconError(Exception): |
