From bde4d729dcd66b468a9d991e8e75e412aa1f13d1 Mon Sep 17 00:00:00 2001 From: kyz Date: Tue, 1 Mar 2022 15:59:02 +0800 Subject: [PATCH] add messagebox for load jsonfile except --- py/cfg_json.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/py/cfg_json.py b/py/cfg_json.py index 0a23edf..dd2113a 100644 --- a/py/cfg_json.py +++ b/py/cfg_json.py @@ -46,9 +46,13 @@ class cfg_json: filepath=askopenfilenames( initialdir=".", title="选择配置文件") if not filepath: return - with open( filepath[0], "r") as fd: - self.jsondata = json.load(fd) - self.cfg_ui.json_update( self.jsondata) + try: + with open( filepath[0], "r") as fd: + self.jsondata = json.load(fd) + self.cfg_ui.json_update( self.jsondata) + except: + messagebox.showwarning(title='', message='加载配置文件失败') + def on_btn_savefile( self ): filepath=asksaveasfilename( filetype=[ ("JsON", "*.json"), ( "All Files", "*")]) @@ -270,7 +274,7 @@ class cfg_json: self.cfg_ui.json_update( self.cfg_data) self.cfg_json_str = self.formate_jsdata( self.cfg_data ) except : - messagebox.showwarning(title='访问设备异常', message='设备通信异常') + messagebox.showwarning(title='', message='设备通信异常') pass #v = dev.read_devinfo_regs() #print( v ) @@ -370,7 +374,7 @@ class cfg_json: dev.write_regs( 8300, [0x0000] ) #save cfg to flash #TODO debug ... except : - messagebox.showwarning(title='访问设备异常', message='设备通信异常') + messagebox.showwarning(title='', message='设备通信异常') pass if __name__ == '__main__': root = Tk() -- 2.34.1