Skip to content

Commit

Permalink
Merge pull request #19 from H1DDENADM1N/gui-tkinter
Browse files Browse the repository at this point in the history
Tree This Folder.exe 增加 gui
  • Loading branch information
imvanda authored Jan 9, 2024
2 parents 1f6b00b + 15c5337 commit a07d4eb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 50 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

![点我.bat预览](assets/点我.bat预览.png)

## 方法 2. 运行 `Tree This Folder.exe`,根据提示输入选项 1 或 2。
## 方法 2. 运行 `Tree This Folder.exe`,根据提示点击按钮或输入快捷键选项 1 或 2。

注意,需同意程序运行时的 🛡️**管理员权限**UAC 授权。

![Tree_This_Folder.exe预览](assets/Tree_This_Folder.exe预览.png)

---

# 🗑️ 移除方法:
Expand All @@ -28,7 +30,7 @@

## 方法 2. 如果添加后已删除文件,可使用 🛡️**管理员权限** 运行 📁`C:\Program Files\Tree This Folder` 文件夹 下的 `remove_treejustcopy.bat``remove_treegenerate.bat`手动移除。

## 方法 3. 运行 `Tree This Folder.exe`,根据提示输入选项 3 或 4。
## 方法 3. 运行 `Tree This Folder.exe`,根据提示点击按钮或输入快捷键选项 3 或 4。

注意,需同意程序运行时的 🛡️**管理员权限**UAC 授权。

Expand Down
Binary file added assets/Tree_This_Folder.exe预览.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dist/Tree This Folder.exe
Binary file not shown.
128 changes: 81 additions & 47 deletions start.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,90 @@
# -*- coding: utf-8 -*-
import ctypes
import os
import sys
import subprocess
import tkinter as tk
from tkinter import ttk

def is_admin():
"""检查用户是否具有管理员权限"""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def run_as_admin(command):
"需要vac"
subprocess.run(["powershell", "Start-Process", command, "-Verb", "RunAs"], shell=True)

def fun1():
run_as_admin(os.path.join(basedir, "复制文件夹结构", "add_treejustcopy.bat"))

def fun2():
run_as_admin(os.path.join(basedir, "生成文件夹结构", "add_treegenerate.bat"))

def fun3():
run_as_admin(os.path.join(basedir, "复制文件夹结构", "remove_treejustcopy.bat"))

def fun4():
run_as_admin(os.path.join(basedir, "生成文件夹结构", "remove_treegenerate.bat"))

class TreeThisFolderApp:
def __init__(self, root):
self.root = root
self.root.title("Tree_This_Folder")
self.root.geometry("303x257")
self.root.resizable(False, False)

self.create_widgets()

def create_widgets(self):
# Configure row and column weights to make buttons expand and center
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_rowconfigure(1, weight=1)
self.root.grid_rowconfigure(2, weight=1)
self.root.grid_rowconfigure(3, weight=1)
self.root.grid_columnconfigure(0, weight=1)



button_width = 35 # Set the desired width for the buttons
button_height = 10 # Set the desired height for the buttons

# Create and define layout for each custom button style
ttk.Style().layout("Custom.TButton1", [("Button.highlight", {"children": [("Button.border", {"children": [("Button.padding", {"children": [("Button.label", {"side": "left", "sticky": ""})]})]})]})])
ttk.Style().layout("Custom.TButton2", [("Button.highlight", {"children": [("Button.border", {"children": [("Button.padding", {"children": [("Button.label", {"side": "left", "sticky": ""})]})]})]})])
ttk.Style().layout("Custom.TButton3", [("Button.highlight", {"children": [("Button.border", {"children": [("Button.padding", {"children": [("Button.label", {"side": "left", "sticky": ""})]})]})]})])
ttk.Style().layout("Custom.TButton4", [("Button.highlight", {"children": [("Button.border", {"children": [("Button.padding", {"children": [("Button.label", {"side": "left", "sticky": ""})]})]})]})])

# Button 1 with color #635994
ttk.Style().configure("Custom.TButton1", foreground="#635994", font=("Microsoft YaHei UI", 12))
self.button1 = ttk.Button(self.root, text=" 1. ➕ 添加 复制文件夹结构", command=fun1, width=button_width)
self.button1.grid(row=0, column=0, pady=0, padx=1, columnspan=3, sticky="nsew")
self.button1.configure(style="Custom.TButton1")
self.root.bind('1', lambda event: fun1()) # Shortcut for Button 1

# Button 2 with color #635994
ttk.Style().configure("Custom.TButton2", foreground="#635994", font=("Microsoft YaHei UI", 12))
self.button2 = ttk.Button(self.root, text=" 2. ➕ 添加 生成文件夹结构", command=fun2, width=button_width)
self.button2.grid(row=1, column=0, pady=0, padx=1, columnspan=3, sticky="nsew")
self.button2.configure(style="Custom.TButton2")
self.root.bind('2', lambda event: fun2()) # Shortcut for Button 2

# Button 3 with color #B0B0B0
ttk.Style().configure("Custom.TButton3", foreground="#B0B0B0", font=("Microsoft YaHei UI", 12))
self.button3 = ttk.Button(self.root, text=" 3. 🗑️ 移除 复制文件夹结构", command=fun3, width=button_width)
self.button3.grid(row=2, column=0, pady=0, padx=1, columnspan=3, sticky="nsew")
self.button3.configure(style="Custom.TButton3")
self.root.bind('3', lambda event: fun3()) # Shortcut for Button 3

# Button 4 with color #B0B0B0
ttk.Style().configure("Custom.TButton4", foreground="#B0B0B0", font=("Microsoft YaHei UI", 12))
self.button4 = ttk.Button(self.root, text=" 4. 🗑️ 移除 生成文件夹结构", command=fun4, width=button_width)
self.button4.grid(row=3, column=0, pady=0, padx=1, columnspan=3, sticky="nsew")
self.button4.configure(style="Custom.TButton4")
self.root.bind('4', lambda event: fun4()) # Shortcut for Button 4

if getattr(sys, 'frozen', None):
basedir = sys._MEIPASS
else:
basedir = os.path.dirname(__file__)

def main():
if not is_admin():
print("错误:此程序需要以管理员权限运行。请以管理员身份重启程序。")
input("按任意键退出...")
return
if getattr(sys, 'frozen', None):
basedir = sys._MEIPASS
else:
basedir = os.path.dirname(__file__)
while True:
# 显示菜单
print("---------------------")
print("1. 添加 复制文件夹结构")
print("2. 添加 生成文件夹结构")
print("3. 移除 复制文件夹结构")
print("4. 移除 生成文件夹结构")
print("0. 退出")
print("---------------------")

choice = input("请输入选项并按Enter键: ")

if choice == "0":
print("退出循环")
break
elif choice == "1":
run_as_admin(basedir + "\\复制文件夹结构\\add_treejustcopy.bat")
elif choice == "2":
run_as_admin(basedir + "\\生成文件夹结构\\add_treegenerate.bat")
elif choice == "3":
run_as_admin(basedir + "\\复制文件夹结构\\remove_treejustcopy.bat")
elif choice == "4":
run_as_admin(basedir + "\\生成文件夹结构\\remove_treegenerate.bat")
else:
print("无效的选项,请重新输入。")

os.system('cls') # 清除屏幕


if __name__ == "__main__":
root = tk.Tk()
app = TreeThisFolderApp(root)
root.iconbitmap(default=os.path.join(basedir, "生成文件夹结构", "TreeThisFolder.ico"))
root.mainloop()

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion start.spec
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ exe = EXE(pyz,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
console=False,
uac_admin=True,
icon='复制文件夹结构/treejustcopy.ico')# 指定应用程序图标

0 comments on commit a07d4eb

Please sign in to comment.