# -*- 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()

wx 文件编辑框的更多相关文章

  1. 在MFC中使用按下按钮出现选择文件对话框,选中一个指定文件,并将其地址显示到指定的编辑框中

    其中,我们选择的文件后缀名为.xlsx,以只读和写操作方式,在所有的文件中选择.xlsl文档 CFileDialog dlg(true, _T(".xlsx"), NULL, OF ...

  2. MFC中打开选择文件夹对话框,并将选中的文件夹地址显示在编辑框中

    一般用于选择你要将文件保存到那个目录下,此程序还包含新建文件夹功能 BROWSEINFO bi; ZeroMemory(&bi, sizeof(BROWSEINFO));  //指定存放文件的 ...

  3. 2.Android之按钮Button和编辑框EditText学习

    今天学习android一些基本控件:button和edittext使用,我们平时网页或者手机登录一般都会有登录框,这里面就用到这两个部件. 如图: 所对应XML文件: 一般第二个编辑框都是输入密码,所 ...

  4. PropertyGrid—为复杂属性提供下拉式编辑框和弹出式编辑框

    零.引言 PropertyGrid中我们经常看到一些下拉式的编辑方式(Color属性)和弹出式编辑框(字体),这些都是为一些复杂的属性提供的编辑方式,本文主要说明如何实现这样的编辑方式. 一.为属性提 ...

  5. 积累的VC编程小技巧之编辑框

    1.如何让对话框中的编辑框接收对话框的消息 ////////////////////////////////////////////////// 如何让对话框中的CEdit控件类接收对话框的消息/// ...

  6. MFC中将编辑框文本转换成整数,从而实现两个整数相加。

    在头文件中,定义三个控件变量,如m_data1,m_data2,m_sum; void Cuse_demo_dllDlg::OnBnClickedButton1(){ CString data1; C ...

  7. [Python] wxPython 编辑框组件学习总结 (原创)

    1.总结 1.常用4种 编辑框 的构造 1.普通编辑框 单行输入的简单编辑框 (?为所在框的对象,同下) self.textBox = wx.TextCtrl(parent = ?) 2.密码编辑框 ...

  8. 怎么编辑PDF文件内容,PDF文件编辑方法

    怎样编辑PDF文件内容?这是一个常常困扰我们的问题,工作当中我们经常会收到PDF格式的文件,但有时的文件内容不是我们想要的或者是觉得不合理的需要改掉.但是每次有这样的问题时都没有什么好的解决方法,每次 ...

  9. iOS 11开发教程(六)iOS11Main.storyboard文件编辑界面

    iOS 11开发教程(六)iOS11Main.storyboard文件编辑界面 在1.2.2小节中提到过编辑界面(Interface builder),编辑界面是用来设计用户界面的,单击打开Main. ...

随机推荐

  1. SpringBoot------Servlet3.0的注解自定义原生Listener监听器

    前言 常用监听器: //contextListener可以监听数据库的连接,第三方组件的交互,还有静态文件加载等等 servletContextListener HttpSessionListener ...

  2. chromedriver与chrome最新版本对应表

    如果需要看到最新版的chromedriver和chrome版本对应问题,点击http://npm.taobao.org/mirrors/chromedriver/,点击最新版本的chromedrive ...

  3. [转]Mariadb的root密码忘记后的解决方法

    环境背景:CentOS 7.2     一.编辑/usr/lib/systemd/system/mariadb.service 文件,在Service段中添加 1 2 3 4 5 6 7 8 9 10 ...

  4. nginx的80端口跳转到443

    然后在80端口设置http跳转到https 在80端口location中加入rewrite ^(.*)$ https://$host$1 permanent; 如图,然后输入命令service ngi ...

  5. rayleighchan实现瑞利多径衰落信

    rayleighchan实现瑞利多径衰落信道 1.命令格式: chan = rayleighchan(ts,fd,tau,pdb) 其中: ts—为输入信号的采样周期, fd—就是Doppler频偏, ...

  6. easyui---表单验证

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  7. AngularJs 常用指令标签

    1.ng-app:告诉Angular他应该管理页面的那一部分,可以放在html元素上也可以放在div等标签上 例:<html ng-app="problem"> 2.n ...

  8. OpenGL开发学习指南二(glfw+glad)

    版权声明:本文为博主原创文章,未经博主允许不得转载.blog.liujunliang.com.cn https://blog.csdn.net/qq_33747722/article/details/ ...

  9. End-to-end and Hop-by-hop Headers ---nginx-websocket

    https://www.oschina.net/translate/websocket-nginx 13.5.1 End-to-end and Hop-by-hop Headers For the p ...

  10. [daily] 使用左右对比查看diff 格式的文件

    如题: Given your references to Vim in the question, I'm not sure if this is the answer you want :) but ...