代码如下:
#!/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()
新闻热点
疑难解答