给我一个pythonGUI代码,我需要两个文件夹选择按钮
时间: 2024-02-03 20:04:12 浏览: 92
好的,以下是一个简单的Python GUI代码,其中包含两个文件夹选择按钮:
```python
import tkinter as tk
from tkinter import filedialog
class FileExplorerGUI:
def __init__(self, master):
self.master = master
master.title("文件夹选择")
self.folder1_path = tk.StringVar()
self.folder2_path = tk.StringVar()
self.folder1_button = tk.Button(master, text="选择文件夹1", command=self.browse_folder1)
self.folder1_button.pack()
self.folder2_button = tk.Button(master, text="选择文件夹2", command=self.browse_folder2)
self.folder2_button.pack()
self.folder1_label = tk.Label(master, textvariable=self.folder1_path)
self.folder1_label.pack()
self.folder2_label = tk.Label(master, textvariable=self.folder2_path)
self.folder2_label.pack()
self.quit_button = tk.Button(master, text="退出", command=master.quit)
self.quit_button.pack()
def browse_folder1(self):
folder1_path = filedialog.askdirectory()
self.folder1_path.set(folder1_path)
def browse_folder2(self):
folder2_path = filedialog.askdirectory()
self.folder2_path.set(folder2_path)
root = tk.Tk()
my_gui = FileExplorerGUI(root)
root.mainloop()
```
这段代码使用了`tkinter`库创建了一个简单的GUI界面,其中包括两个文件夹选择按钮,点击按钮后会弹出文件夹选择框。选择完成后,选择的文件夹路径会显示在标签上。
阅读全文