首页 技术 正文
技术 2022年11月14日
0 收藏 970 点赞 4,439 浏览 1842 个字
# -*- coding: utf- -*-
import wx
import os
class my_frame(wx.Frame):
"""This is a simple text editor"""
def __init__(self,parent, title):
wx.Frame.__init__(self, parent, title=title,size=(,))
self.control = wx.TextCtrl(self, -,"请先打开要修改的文件", style=wx.TE_MULTILINE,)
self.Show(True)
self.CreateStatusBar()#创建窗口底部的状态栏 filemenu = wx.Menu()
menu_open = filemenu.Append(wx.ID_OPEN, "打开文件", " ")
menu_save = filemenu.Append(wx.ID_SAVE, "保存修改",)
menu_exit = filemenu.Append(wx.ID_EXIT, "Exit", "Termanate the program")
filemenu.AppendSeparator()
menu_about = filemenu.Append(wx.ID_ABOUT, "About", "Information about this program")#设置菜单的内容 menuBar = wx.MenuBar()
menuBar.Append(filemenu, "选项")
self.SetMenuBar(menuBar)#创建菜单条
self.Show(True) self.Bind(wx.EVT_MENU, self.on_open, menu_open)
self.Bind(wx.EVT_MENU, self.on_about, menu_about)
self.Bind(wx.EVT_MENU, self.on_exit, menu_exit)#把出现的事件,同需要处理的函数连接起来
self.Bind(wx.EVT_MENU, self.on_save, menu_save) def on_about(self,e):#about按钮的处理函数
dlg = wx.MessageDialog(self,"A samll text editor", "About sample Editor",wx.OK)#创建一个对话框,有一个ok的按钮
dlg.ShowModal()#显示对话框
dlg.Destroy()#完成后,销毁它。 def on_exit(self,e):
self.Close(True) def on_open(self,e):
"""open a file""" dlg = wx.FileDialog(self,
message="Choose a file",
defaultDir="",
defaultFile="",
wildcard="*.*",
style=wx.FD_OPEN | wx.FD_CHANGE_DIR)#调用一个函数打开对话框 if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
self.address = os.path.join(self.dirname,self.filename)
f = open(self.address,"r")
file = (f.read()) #python3 不需要解码
f.close()
self.control.Clear()
self.control.AppendText(file)#把打开的文件内容显示在多行文本框内
dlg.Destroy() def on_save(self, e):
date = (self.control.GetValue()) #python3 不需要编码
f = open(self.address, 'w')
f.write(date)
f.close()#把文本框内的数据写入并关闭文件
dlg = wx.MessageDialog(self, "文件已经成功保存", "消息提示", wx.OK)
dlg.ShowModal()
dlg.Destroy()
self.control.Clear()
self.control.AppendText('欢迎使用此软件,作者即刻')app = wx.App(False)
frame = my_frame(None, '迷你文本编辑器')
app.MainLoop()
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848