-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from H1DDENADM1N/gui-tkinter
Tree This Folder.exe 增加 gui
- Loading branch information
Showing
5 changed files
with
86 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters