def main(*args): global root from my_class import Clan from my_constant import config, clanname myclan = Clan(clanname) myclan.initialize() import tkinter def MakeRoot(c=[0]): if not '%s'%c[0] in _root_dict: _root_dict['%s'%c[0]] = tkinter.Tk(className='Manager%s'%c[0]) result = _root_dict['%s'%c[0]] # c[0] += 1 return result root = MakeRoot() root.clan = myclan root.wm_iconbitmap(default=config['icon']) root.withdraw() root.onoroff = 1 root.wcount = 0 # 读取文件 import traceback import tkinter.messagebox import os import my_io if args: #tkinter.messagebox.showinfo('args',str(sys.argv)+'\n'+str(args)) myclan.clearh() myclan.cleard() for file in args: try: if os.path.splitext(file)[1]=='.clh': myclan.addh(my_io.read_history(myclan, file)) elif os.path.splitext(file)[1]=='.cld': myclan.addd(my_io.read_donate(myclan, file)) except Exception as e: traceback.print_exc() tkinter.messagebox.showerror('文件出错!','打开失败') else: tkinter.messagebox.showinfo('成功!', '%s已读入!'%file) else: myclan.clearh() myclan.cleard() for file in ('data.cld', 'history.clh'): file = os.path.join('save',file) if os.path.exists(file): if os.path.splitext(file)[1]=='.clh': myclan.addh(my_io.read_history(myclan, file)) elif os.path.splitext(file)[1]=='.cld': myclan.addd(my_io.read_donate(myclan, file)) # 主循环 from my_widget import MainWindows MainWindows(root) while root.onoroff: root.mainloop() try:root.destroy() except:pass
def save(self): # 保存操作 import traceback import my_io import tkinter try: import tkinter.filedialog except: pass import my_constant if all(self.FlagList): if tkinter.messagebox.askyesno('确认',\ '你确定要保存吗?如果文件已不存在将自动创建。'): path = tkinter.filedialog.asksaveasfilename(**my_constant.history_opt) if path: try: my_io.append_history(self.clan.imah, path) except Exception as e: traceback.print_exc() tkinter.messagebox.showerror('出错了!', '保存失败') else: self.clan.addh(my_io.read_history(self.clan, path)) path = tkinter.filedialog.asksaveasfilename(**my_constant.donate_opt) if path: try: my_io.append_donate(self.clan.imad, path) except Exception as e: traceback.print_exc() tkinter.messagebox.showerror('出错了!', '保存失败') else: self.clan.addd(my_io.read_donate(self.clan, path)) else: tkinter.messagebox.showerror('出错了!', '信息不完整!战斗结束请添加"end"')
def read_h(self): import tkinter.messagebox as messagebox import tkinter.filedialog as filedialog import my_constant import my_io import traceback try: f = filedialog.askopenfilename(**my_constant.history_opt) if f: self.clan.clearh() self.clan.addh(my_io.read_history(self.clan, f)) except Exception as e: print(traceback.print_exc()) messagebox.showerror('文件出错!',\ '你的文件有问题,管Ceilopty再要一份!') else: if f: messagebox.showinfo('成功!', '对战历史信息已读入!') self.master.master.focus_force()