tkinter蓝光记事本.py

tkinter蓝光记事本.py

李兴球python可视化tkinter记事本开发

"""
   蓝光记事本.py
   一个简单的记事本,还没有添加右键菜单。
"""
import tkinter as tk
from tkinter import messagebox
from tkinter.filedialog import askopenfilename, asksaveasfilename

def open_file():
    """打开文件进行编辑"""
    filepath = askopenfilename( filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
    if not filepath: return                    # 如果此文件不存在,直接返回
    txt_editor.delete(1.0, tk.END)             # 删除文本框所有内容
    with open(filepath, "r") as input_file:
        text = input_file.read()
        txt_editor.insert(tk.END, text)
    window.title(f"{filepath} 蓝光记事本")

def save_file():
    """保存文件"""
    filepath = asksaveasfilename(defaultextension="txt",
        filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")], )
    if not filepath: return
    with open(filepath, "w") as output_file:
        text = txt_editor.get(1.0, tk.END)
        output_file.write(text)
    window.title(f"{filepath} 蓝光记事本")

window = tk.Tk()
window.title("蓝光记事本 www.lixingqiu.com")
window.rowconfigure(0, minsize=800, weight=1)
window.columnconfigure(1, minsize=800, weight=1)

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客