• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python写的一个文本编辑器

python写的一个文本编辑器

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python文本编辑器,python文本编辑器下载,python3文本编辑器,python编写文本编辑器,c语言写文本编辑器等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

from Tkinter import *
import tkMessageBox,tkFileDialog
import platform

# nl = os.linesep

def openfile():
    global filename             # 使用global声明为全局变量,方便后边的程序调用
    systype = platform.system() # 判断系统类型
    if systype == 'windows':
        basedir = 'c:\\'
    else:
        basedir = '/'
    filename = tkFileDialog.askopenfilename(initialdir=basedir)
    try:
        fobj_r = open(filename, 'r')
    except IOError, errmsg:
        print '*** Failed open file:', errmsg
    else:
        editbox.delete(1.0, END)
        for eachline in fobj_r:
            editbox.insert(INSERT, eachline)
        fobj_r.close()

def savefile():
    save_data = editbox.get(1.0, END)
    try:
        fobj_w = open(filename, 'w')
        fobj_w.writelines(save_data.encode('utf-8'))
        fobj_w.close()
        tkMessageBox.showinfo(title='提示',
                message='保存成功')
    except IOError, errmsg:
        tkMessageBox.showwarning(title='保存失败', message='保存出错    ')
        tkMessageBox.showwarning(title='错误信息', message=errmsg)
    except NameError:
        tkMessageBox.showwarning(title='保存失败', message='未打开文件')
def showlinenum():
    tkMessageBox.showinfo(title='提示',
            message='这个功能作者现在不会写,放这里装饰用的.')
def destroy_ui(ui):
    ui.destroy()

def aboutauthor():
    author_ui = Toplevel()
    author_ui.title('关于')
    author_ui.geometry('200x80')
    about_string = Label(author_ui,
            text="作者: ToughGuy")
    confirmbtn = Button(author_ui, text='确定',
            command=lambda:destroy_ui(author_ui))
    about_string.pack()
    confirmbtn.pack()
    # author_ui.mainloop()

def CreateMenus():
    # 初始化菜单
    Menubar = Menu(root)

    # 创建文件菜单
    filemenu = Menu(Menubar, tearoff=0)
    filemenu.add_command(label='打开文件', command=openfile)
    filemenu.add_command(label='保存文件', command=savefile)
    filemenu.add_command(label='退出', command=lambda:destroy_ui(root))
    Menubar.add_cascade(label='文件', menu=filemenu)

    # 创建编辑菜单
    editmenu = Menu(Menubar, tearoff=0)
    editmenu.add_command(label='显示行号', command=showlinenum)
    Menubar.add_cascade(label='编辑', menu=editmenu)

    # 创建帮助菜单
    helpmenu = Menu(Menubar, tearoff=0)
    helpmenu.add_command(label='关于作者', command=aboutauthor)
    Menubar.add_cascade(label='帮助', menu=helpmenu)
    root.config(menu=Menubar)

root = Tk()
root.title('文本编辑器')
root.geometry('500x400')
CreateMenus()
editbox = Text(root, width=70, height=25, bg='white')
editbox.pack(side=TOP, fill=X)
root.mainloop()
</div>

</div>

您可能想查找下面的文章:

  • Python简单检测文本类型的2种方法【基于文件头及cchardet库】
  • Python简单检测文本类型的2种方法【基于文件头及cchardet库】
  • Python如何实现文本转语音
  • Python读写txt文本文件的操作方法全解析
  • Python的Flask站点中集成xhEditor文本编辑器的教程
  • Python的Flask站点中集成xhEditor文本编辑器的教程
  • Python判断文本中消息重复次数的方法
  • Python判断文本中消息重复次数的方法
  • 使用Python读写文本文件及编写简单的文本编辑器
  • 使用Python读写文本文件及编写简单的文本编辑器

相关文章

  • 由浅入深讲解python中的yield与generator
  • python回溯法实现数组全排列输出实例分析
  • Windows安装Python、pip、easy_install的方法
  • Python映射拆分操作符用法实例
  • python实现在字符串中查找子字符串的方法
  • Python中函数的用法实例教程
  • python 多进程通信模块的简单实现
  • Python3.2模拟实现webqq登录
  • 在Python的Django框架中用流响应生成CSV文件的教程
  • Python实现二叉堆

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • pycharm安装图文教程
    • python使用paramiko模块实现ssh远程登陆上传文件并执行
    • Python常用模块介绍
    • python获取当前用户的主目录路径方法(推荐)
    • Python常用小技巧总结
    • python实现FTP服务器服务的方法
    • Python使用scrapy采集时伪装成HTTP/1.1的方法
    • python中的列表推导浅析
    • 简单的抓取淘宝图片的Python爬虫
    • python正则表达式之作业计算器

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有