tkinter打开文件资源管理器
时间: 2023-12-03 09:39:47 浏览: 196
您可以使用Tkinter模块创建一个简单的文件资源管理器界面。通过打开文件夹按钮,使用`filedialog`模块选择指定文件夹作为当前目录文件。以下是一个简单的示例代码:
```python
from tkinter import *
from tkinter import filedialog
class FileManager:
def __init__(self, window):
self.window = window
self.window.title("文件资源管理器")
self.current_dir = ""
self.open_button = Button(self.window, text="打开", command=self.open_dir)
self.open_button.pack(pady=10)
self.quit_button = Button(self.window, text="退出", command=self.quit)
self.quit_button.pack(pady=10)
def open_dir(self):
folder_path = filedialog.askdirectory()
if folder_path:
self.current_dir = folder_path
self.listbox.delete(0, END)
for file in os.listdir(folder_path):
self.listbox.insert(END, file)
def quit(self):
self.window.destroy()
root = Tk()
fm = FileManager(root)
root.mainloop()
```
阅读全文
相关推荐


















