Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit 78a71a3

Browse files
committed
File select. May work with updated asynctk
1 parent fe4d24f commit 78a71a3

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

main.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
11
import asynctk as tk
22
import asyncio
3+
import os
4+
import pathlib
35

46
root = tk.AsyncTk()
7+
8+
async def file_select():
9+
manager = tk.AsyncToplevel(root)
10+
dir = pathlib.PurePath()
11+
dirbox = tk.AsyncEntry(manager)
12+
dirbox.grid(row=0, column=0)
13+
foldermap = tk.AsyncFrame(manager)
14+
foldermap.grid(row=1,column=0)
15+
def populate_folder(folder):
16+
nonlocal dir
17+
dir = manager.dir
18+
for i in os.listdir(folder):
19+
if (dir / i).is_file():
20+
async def cb():
21+
manager.file = dir / i
22+
await manager.destroy()
23+
tk.AsyncButton(foldermap, text=f'{i} [FILE]', callback=cb).pack()
24+
if (dir / i).is_dir():
25+
async def cb():
26+
manager.dir = dir / i
27+
populate_folder(manager.dir)
28+
tk.AsyncButton(foldermap, text=f'{i} [FOLDER]',callback=cb).pack()
29+
def boxcallback(*i):
30+
change_dir(dirbox.get())
31+
def change_dir(path):
32+
nonlocal dir, foldermap
33+
dir = pathlib.PurePath(path)
34+
manager.dir = dir
35+
asyncio.ensure_future(foldermap.destroy())
36+
foldermap = tk.AsyncFrame(manager)
37+
foldermap.grid(row=1,column=0)
38+
populate_folder(dir)
39+
40+
dirbox.bind('<Return>', boxcallback)
41+
await root.wait_window(manager)
42+
return manager.dir
43+
44+
545
async def save():
6-
print('test')
46+
print(await file_select())
47+
48+
749
root.protocol("WM_DELETE_WINDOW", lambda: asyncio.ensure_future(save()))
8-
root.mainloop()
50+
51+
52+
root.menu = tk.AsyncMenu(root)
53+
root.config(menu=root.menu)
54+
55+
56+
root.dropdown = tk.AsyncMenu(root.menu)
57+
58+
root.dropdown.add_command(label="Do nothing", command=lambda: None)
59+
root.dropdown.add_command(
60+
label="Save processor time", command=lambda: asyncio.ensure_future(root.destroy())
61+
)
62+
63+
root.menu.add_cascade(label="Unhelpful menu", menu=root.dropdown)
64+
65+
66+
root.mainloop()

0 commit comments

Comments
 (0)