python写的一个文本编辑器
代码如下:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#=============================================================================
# FileName:
# Desc:
# Author: ToughGuy
# Version: 0.0.1
# LastChange: 2013-02-20 14:52:11
# History:
#=============================================================================
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()

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Linux終端中查看Python版本時遇到權限問題的解決方法當你在Linux終端中嘗試查看Python的版本時,輸入python...

使用FiddlerEverywhere進行中間人讀取時如何避免被檢測到當你使用FiddlerEverywhere...

在使用Python的pandas庫時,如何在兩個結構不同的DataFrame之間進行整列複製是一個常見的問題。假設我們有兩個Dat...

如何在10小時內教計算機小白編程基礎?如果你只有10個小時來教計算機小白一些編程知識,你會選擇教些什麼�...

Uvicorn是如何持續監聽HTTP請求的? Uvicorn是一個基於ASGI的輕量級Web服務器,其核心功能之一便是監聽HTTP請求並進�...

攻克Investing.com的反爬蟲策略許多人嘗試爬取Investing.com(https://cn.investing.com/news/latest-news)的新聞數據時,常常�...
