def save_file(): #保存图片 img1_BGR = cv2.cvtColor(img1_RGBA, cv2.COLOR_RGBA2BGR) choice = dialog.Dialog( None, { 'title': 'File Modified', 'text': '注意路径中不能含有中文字符!', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancel') }) if choice.num == 0: file_path = filedialog.asksaveasfilename(title=u'保存文件') try: print('保存文件:', file_path) cv2.imwrite(filename=file_path, img=img1_BGR) dialog.Dialog( None, { 'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) print('保存完成') except: print('Close by user or use the wrong path.')
def save_file(): #保存图片 img1_BGR = cv2.cvtColor(img1_RGBA, cv2.COLOR_RGBA2BGR) dialog.Dialog( None, { 'title': 'File Modified', 'text': '注意路径中不能含有中文字符!请务必添加后缀名!', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancel') }) file_path = filedialog.asksaveasfilename(title=u'保存文件') try: print('保存文件:', file_path) cv2.imwrite(filename=file_path, img=img1_BGR) dialog.Dialog( None, { 'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) print('保存完成') except: dialog.Dialog( None, { 'title': 'File Modified', 'text': '请输入可用路径', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') })
def open_file(): global file_path global file_text global twi global data file_path = filedialog.askopenfilename( title=u'Choose file', initialdir=(os.path.expanduser('H:/'))) print('Open File:', file_path) file_text = load_csv(file_path) for i in range(len(file_text)): file_text[i] = file_text[i].lower() file_text[i] = re.sub( "[\.\!\[\]\-\=\;\{\}\/_,$%^*(+\"\')]+|[+——()?【】“”!,。?、~@#¥%……&*()]", "", file_text[i]) twi.append(file_text[i].split()) data = loadTwee(twi) dialog.Dialog( None, { 'title': 'File Open', 'text': 'Load Complete!', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) print('Load Complete!')
def play_mode(self): # 获得玩家选择的对战模式 mode_id = self.mode_var.get() mode_value = '双人' if mode_id == 2 else '人机' # 当前为人机模式,玩家切换为双人模式,或者当前为双人模式,玩家切换为人机模式 if (self.is_player_vs_computer is True and mode_id == 2) or ( self.is_player_vs_computer is False and mode_id == 1): # 弹框提示 dialog_value = { 'title': '切换游戏模式', 'text': f"切换游戏模式则当前正在进行的游戏将不能保存,确定要切换到{mode_value}对战模式吗?", 'bitmap': 'warning', 'default': 1, 'strings': ('确定', '取消') } d = dialog.Dialog(self.master, dialog_value) # 选择确定按钮 if d.num == 0: # 重新开始游戏 self.reset_game_start(write_won='', is_normal_over=False) # 更改对战模式的状态 if mode_id == 1: self.is_player_vs_computer = True self.begin_str = "*" * 20 + '人机对战模式' + "*" * 20 + '\n' self.log.info('切换人机对战模式!!') else: self.is_player_vs_computer = False self.begin_str = "*" * 20 + '双人对战模式' + "*" * 20 + '\n' self.log.info('切换双人对战模式!!') # 写入info文件 self.begin_str += "*" * 20 + setting.begin_str + "*" * 20 common.write_file(filename=self.info_file, write_value=self.begin_str)
def judge_database(database, root): # 返回系统中的数据库列表 # Returns a list of databases in the system db_list = client.list_database_names() if database in db_list: # 使用dialog.Dialog创建对话框 d = dialog.Dialog( root, # 设置该对话框所属的窗口 { 'title': 'Tip', # 标题 'text': "The database is already existed! \n" "Delete existed database? \n" "OR\n" "Rename your database?", # 内容 'bitmap': 'warning', # 图标 'default': '', # 设置默认选中项 'strings': ('Delete', 'Rename') }) if d.num == 0: client.drop_database(database) return False else: return True else: return False
def close_window(self): dialog_value = { 'title': '退出游戏', 'text': '游戏正在进行中,确定要退出吗?', 'bitmap': 'question', 'default': 0, 'strings': ('确定', '取消') } d = dialog.Dialog(self.master, dialog_value) if d.num == 0: # 退出系统之前记录本轮游戏的结果 game_end_time = datetime.now() # 游戏共经历了多少时长 how_long = common.how_long_time(self.game_begin_time, game_end_time) # 记录游戏局数和胜利的玩家信息 game_over_str = "*" * 20 game_over_str += f"本轮游戏时长为{how_long},总共完成{self.totalCount}局" if self.totalCount != 0: if self.Player1WonCount > self.Player2WonCount: game_over_str += f",其中[{setting.player1_name}]技高一筹,胜 {self.Player1WonCount} 局" elif self.Player1WonCount < self.Player2WonCount: game_over_str += f",其中[{setting.player2_name}]技高一筹,胜 {self.Player2WonCount} 局" else: game_over_str += f",两位玩家旗鼓相当,均胜 {self.Player1WonCount} 局" if self.tieCount != 0: game_over_str += f",打平 {self.tieCount} 局" game_over_str += "*" * 20 common.write_file(filename=self.info_file, write_value=game_over_str) self.log.info(game_over_str) # play_music.quit_music() self.log.info("游戏退出!") self.master.destroy()
def save_file(): global file_path global file_text file_path = filedialog.asksaveasfilename(title=u'Store File') print('Store File:', file_path) output = text1.get('1.0', tk.END) if file_path is not None: with open(file=file_path, mode='w+', encoding='utf-8') as file: file.writelines(str(len(twi))) file.writelines("\n") for line in twi: outline = str(len(line)) for word in line: outline = outline + " " + word file.writelines(outline) file.writelines("\n") text1.delete('1.0', tk.END) dialog.Dialog( None, { 'title': 'File Modified', 'text': 'Store Complete!', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) print('Store Complete!')
def callback_customized_dialog(): dialog = tdialog.Dialog(None, title='Customized Dialog', text='This is a customized dialog', bitmap=tdialog.DIALOG_ICON, default=0, strings=('Yes', 'No', 'Cancel')) print(dialog.num)
def help(self): #帮助按钮弹出的dialog d = DL.Dialog(None, title='使用帮助', text='1.尽量使用尺寸相同的图像进行混合\n2.仅前三种混合模式可调节混合度\n3.目前只支持RGB' '模式的JPEG图像', bitmap=DL.DIALOG_ICON, default=0, strings=('好的', '关闭'))
def help(self): """Help for the widget.""" d = dialog.Dialog(None, {"title": "Viewer help", "text": "Button-1: Translate\n" "Button-2: Rotate\n" "Button-3: Zoom\n" "Reset: Resets transformation to identity\n", "bitmap": "questhead", "default": 0, "strings": ("Done", "Ok")}) assert d
def help(self): """Help for the widget.""" d = dialog.Dialog(None, {'title': 'Viewer help', 'text': 'Button-1: Translate\n' 'Button-2: Rotate\n' 'Button-3: Zoom\n' 'Reset: Resets transformation to identity\n', 'bitmap': 'questhead', 'default': 0, 'strings': ('Done', 'Ok')}) assert d
def end_game(self, win: bool) -> None: """ Called when end game logic occurred, either win or lose. :param win: True = win, False = lose """ if win: title = "You won!" msg = "Good job. Play again?" strings = ('New Game', 'Quit') question = tkdiag.Dialog(title=title, text=msg, bitmap="question", strings=strings, default=0) ans = strings[question.num] if ans == strings[0]: self.start_new_game() elif ans == strings[1]: sys.exit() else: title = "You lost..." if self.model.undos_remaining > 0: msg = f"You have {self.model.undos_remaining} undos remaining.\nDo you want to undo last move?" strings = ('Undo', 'New Game', 'Quit') question = tkdiag.Dialog(title=title, text=msg, bitmap="question", strings=strings, default=0) ans = strings[question.num] if ans == strings[0]: self.undo_state() elif ans == strings[1]: self.start_new_game() elif ans == strings[2]: sys.exit() else: msg = f"You have {self.model.undos_remaining} undos remaining.\nDo you want to play a new game?" strings = ('New Game', 'Quit') question = tkdiag.Dialog(title=title, text=msg, bitmap="question", strings=strings, default=0) ans = strings[question.num] if ans == strings[0]: self.start_new_game() elif ans == strings[1]: sys.exit()
def open_dialog(self): # 使用dialog.Dialog创建对话框 d = dialog.Dialog( self.master # 设置该对话框所属的窗口 , { 'title': 'Dialog测试', # 标题 'text': self.msg, # 内容 'bitmap': 'question', # 图标 'default': 0, # 设置默认选中项 # strings选项用于设置按钮 'strings': ('确定', '取消', '退出') }) print(d.num) #②
def open_file(): #读取读者自定义的贴纸 dialog.Dialog( None, { 'title': 'File Modified', 'text': '注意路径中不能含有中文字符!', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancel') }) selfcustomizesticker_path = tk.filedialog.askopenfilename(title=u'打开贴图') selfcustomizeSticker = Sticker(name='selfcustomizeSticker', path=selfcustomizesticker_path, faceSpot=[0, 0], stickerSpot=[0, 0]) selfcustomizeSticker.createButton(1, 10)
def out(self): from tkinter import filedialog, dialog file_path = filedialog.asksaveasfilename(title=u'保存文件') file_text = self.output.get('1.0', END) if file_path is not None: with open(file=file_path, mode='a+', encoding='utf-8') as file: file.write('word' + '\t' + 'pcPV' + '\t' + 'mobPV' + '\t' + 'totalPV' + '\n') file.write(file_text) dialog.Dialog( None, { 'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': 'OK' })
def save_file(): global file_path global file_text file_path = filedialog.asksaveasfilename(title=u'save files') print('保存文件:', file_path) file_text = text2.get('2.0', 'end') if file_path is not None: with open(file=file_path, mode='a+', encoding='utf-8') as file: file.write(file_text) dialog.Dialog( None, { 'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'cancel') }) print('保存完成')
def save_file(): global file_path global file_text file_path = filedialog.asksaveasfilename(title=u'save file') print('saving file:', file_path) file_text = text1.get('1.0', tk.END) if file_path is not None: with open(file=file_path, mode='a+', encoding='utf-8') as file: file.write(file_text) text1.delete('1.0', tk.END) dialog.Dialog( None, { 'title': 'File Modified', 'text': 'finish saving', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) print('finish saving file')
def question1(dedo): d = dialog.Dialog( None, { 'title': 'Question', 'text': 'Which Type Of Task You Want To Do In This Selected Playlist'. title(), 'bitmap': dialog.DIALOG_ICON, 'default': 'None', 'strings': ('Open', 'Edit Name', 'Delete!') }) if d.num == 0: open__() if d.num == 1: edit() if d.num == 2: pass
def output_result_file(self): file_path = filedialog.asksaveasfilename(title=u'保存文件') #print('保存文件:', file_path) file_text = self.result_data_Text.get(1.0, END) if file_path is not None: try: with open(file=file_path, mode='w', encoding='utf-8') as file: file.write(file_text) self.result_data_Text.delete(1.0, END) dialog.Dialog( None, { 'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) utils.write_log_to_Text(self.log_data_Text, '保存完成,文件路径:' + file_path) except Exception as e: utils.write_log_to_Text(self.log_data_Text, e)
def open_file(): #读取读者自定义的贴纸 choice = dialog.Dialog( None, { 'title': 'File Modified', 'text': '图片路径中不能含有中文字符!', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) if choice.num == 0: global selfcustomizeSticker selfcustomizesticker_path = tk.filedialog.askopenfilename( title=u'打开贴图') selfcustomizeSticker = Sticker(name='selfcustomizeSticker', path=selfcustomizesticker_path, faceSpot=[0, 0], stickerSpot=[0, 0]) selfcustomizeSticker.createButton() label = tk.Label(root, text="从此处按住开始拖动自定义贴纸") label.grid() label.bind("<B1-Motion>", moveimg)
def savelocaol(): ####################### # head=headinput.get() # tail=tailinput.get() # TOTAL=TELnuminput.get() # # lenhead = len(head) # lentail = len(tail) # lenlast = 11 - lenhead - lentail # Uset = UniqueStr(int(TOTAL), lenlast) # LastSet = set() # for item in Uset: # TELnum = head + item + tail # LastSet.add(TELnum) ####################### # 第二次更改需要直接路径 # filepath=saveinput.get() # fo = open(filepath, "w") # fo.write(showTel.get('0.0','end')) #################################### file_path = filedialog.asksaveasfilename(title="保存文件") file_text = showTel.get('0.0', 'end') if file_path is not None: with open(file=file_path, mode='a+', encoding='utf-8') as file: file.write(file_text) # 保存之后就清空 # showTel.delete(1.0,"end") dialog.Dialog( None, { 'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle') }) print("保存完成")