@@ -8,10 +8,10 @@ class ConfigEditor:
88 def __init__ (self , root ):
99 self .root = root
1010 self .root .title ("Office Backup Utility Config Editor" )
11- self .root .geometry ("700x400 " )
11+ self .root .geometry ("700x450 " )
1212 self .root .resizable (True , True )
1313 # 设置窗口最小尺寸
14- self .root .minsize (600 , 400 )
14+ self .root .minsize (700 , 450 )
1515
1616 # 使用系统默认字体
1717 self .font = None
@@ -102,7 +102,7 @@ def create_widgets(self):
102102 button_frame .pack (side = tk .RIGHT , padx = 5 , pady = 5 , fill = tk .Y )
103103
104104 # 其他按钮
105- ttk .Button (button_frame , text = "启动 " , command = self .start_program , takefocus = False ,width = 5 ).pack (side = tk .RIGHT , padx = 5 , fill = tk .Y )
105+ ttk .Button (button_frame , text = "一键启动 " , command = self .start_program , takefocus = False , width = 10 ).pack (side = tk .RIGHT , padx = 5 , fill = tk .Y )
106106 # 键名显示模式切换按钮
107107 initial_text = "切换到原始键名" if self .key_name_mode == "simple" else "切换到简明键名"
108108 self .key_name_button = ttk .Button (button_frame , text = initial_text , command = self .toggle_key_name_mode , takefocus = False )
@@ -875,25 +875,42 @@ def start_program(self):
875875
876876 # 根据版本确定程序文件
877877 program_files = {
878- "5.0" : "OfficebackupSingle5.0.py " ,
879- "6.0" : "Officebackup6.0.py " ,
880- "6.0Core" : "Officebackup6.0Core.py "
878+ "5.0" : "OfficebackupSingle5.0" ,
879+ "6.0" : "Officebackup6.0" ,
880+ "6.0Core" : "Officebackup6.0Core"
881881 }
882882
883883 if version in program_files :
884- program_file = program_files [version ]
885- if os .path .exists (program_file ):
886- # 启动程序
884+ base_name = program_files [version ]
885+ # 优先尝试启动 py 文件
886+ py_file = f"{ base_name } .py"
887+ if os .path .exists (py_file ):
888+ # 启动 py 文件
887889 try :
888890 import subprocess
889- subprocess .Popen (["python" , program_file ])
891+ subprocess .Popen (["python" , py_file ])
892+ self .status_var .set (f"已启动{ version } 版本程序" )
893+ messagebox .showinfo ("成功" , f"已启动{ version } 版本程序" )
894+ return
895+ except Exception as e :
896+ messagebox .showerror ("错误" , f"启动程序失败: { str (e )} " )
897+ self .status_var .set ("启动程序失败" )
898+ return
899+
900+ # 如果 py 文件不存在,尝试启动 exe 文件
901+ exe_file = f"{ base_name } .exe"
902+ if os .path .exists (exe_file ):
903+ # 启动 exe 文件
904+ try :
905+ import subprocess
906+ subprocess .Popen ([exe_file ])
890907 self .status_var .set (f"已启动{ version } 版本程序" )
891908 messagebox .showinfo ("成功" , f"已启动{ version } 版本程序" )
892909 except Exception as e :
893910 messagebox .showerror ("错误" , f"启动程序失败: { str (e )} " )
894911 self .status_var .set ("启动程序失败" )
895912 else :
896- messagebox .showerror ("错误" , f"程序文件不存在: { program_file } " )
913+ messagebox .showerror ("错误" , f"程序文件不存在: { py_file } 或 { exe_file } " )
897914 self .status_var .set ("程序文件不存在" )
898915 else :
899916 messagebox .showerror ("错误" , "无效的版本" )
0 commit comments