tkinter介紹
tkinter是python自帶的GUI庫,是對圖形庫TK的封裝
tkinter是一個跨平臺的GUI庫,開發的程序可以在win,linux或者mac下運行
# !/user/bin/env Python3 # -*- coding:utf-8 -*- """ file:window.py.py create time:2019/6/27 14:54 author:Loong Xu desc: 窗口 """ import tkinter as tk from tkinter import filedialog, dialog import os window = tk.Tk() window.title('窗口標題') # 標題 window.geometry('500x500') # 窗口尺寸 file_path = '' file_text = '' text1 = tk.Text(window, width=50, height=10, bg='orange', font=('Arial', 12)) text1.pack() def open_file(): ''' 打開文件 :return: ''' global file_path global file_text file_path = filedialog.askopenfilename(title=u'選擇文件', initialdir=(os.path.expanduser('H:/'))) print('打開文件:', file_path) if file_path is not None: with open(file=file_path, mode='r+', encoding='utf-8') as file: file_text = file.read() text1.insert('insert', file_text) def save_file(): global file_path global file_text file_path = filedialog.asksaveasfilename(title=u'保存文件') print('保存文件:', 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': '保存完成', 'bitmap': 'warning', 'default': 0, 'strings': ('OK', 'Cancle')}) print('保存完成') bt1 = tk.Button(window, text='打開文件', width=15, height=2, command=open_file) bt1.pack() bt2 = tk.Button(window, text='保存文件', width=15, height=2, command=save_file) bt2.pack() window.mainloop() # 顯示
網頁標題:Python3tkinter實現文件讀取及保存功能-創新互聯
網頁地址:http://vcdvsql.cn/article48/cdichp.html
成都網站建設公司_創新互聯,為您提供定制開發、企業建站、網站設計、網站收錄、外貿建站、建站公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯