python用Tkinter做自己的中文代码编辑器
作者:荷蒲 发布时间:2023-08-12 05:32:33
标签:Tkinter,中文代码编辑器
前面我们给了Tkinter接管Python输入和输出的介绍,我们不难可以想到,能用Tkinter来开发自己的Python代码编辑器.例如可以使用Text控件作代码编辑器.
实际上我在HP_tk2中已经封装好了现成的中文Python代码编辑器组件和防Ipython功能的组件,另用这2个组件很容易搭建出自己的代码编辑器.
下面直接给出完整演示源代码.
#中文可视化Python开发系统.py
import tkinter as tk #导入Tkinter
import tkinter.ttk as ttk #导入Tkinter.ttk
import tkinter.tix as tix #导入Tkinter.tix
from tkinter.filedialog import *
from tkinter.messagebox import *
import PIL
from PIL import Image, ImageTk, ImageDraw, ImageFont
import HP_tk2 as htk #导入htk
import webbrowser
import os
import sys
import threading
import time
#建立应用窗口
root=htk.MainWindow(title='中文Python代码编辑器',x=0,y=0,w=1200, h=800,picture='',zoom=True,center=True)
root.iconbitmap('ico/cp64.ico') #设置应用程序图标
root.SetCenter() #移动到屏幕中央
#建立菜单
menus = [['文件',['执行程序','-','新建','打开','运行','-','保存','另存为']],\
['编辑',['撤销','重做','-','剪切','复制','粘贴','清除','-','全选']],\
['显示',['绘图','表格']],\
['程序',['运行','编译']],\
['项目',['工程设置','系统设置']],\
['数据',['连接行情服务器','断开行情服务器','下载股票代码表','下载财务数据',\
'下载板块数据']],\
['帮助',['关于软件','退出']]]
mainmenu=htk.windowMenu(root,menus) #窗口菜单
toolsbar=htk.ToolsBar(root,6,bg='yellow') #创建工具栏,参数1-20
toolsbar.pack(side=tk.TOP, fill=tk.X)
#改变工具条图标
png1= PIL.ImageTk.PhotoImage(PIL.Image.open('ico/New2.ico'))
png2= PIL.ImageTk.PhotoImage(PIL.Image.open('ico/APS0.ico'))
png3= PIL.ImageTk.PhotoImage(PIL.Image.open('ico/class.ico'))
png4= PIL.ImageTk.PhotoImage(PIL.Image.open('ico/clxokcnhlp1.ico'))
png5= PIL.ImageTk.PhotoImage(PIL.Image.open('ico/Table.ico'))
toolsbar.config(0,image=png1)
toolsbar.config(1,image=png2)
toolsbar.config(2,image=png3)
toolsbar.config(3,image=png4)
toolsbar.config(4,image=png5)
#创建状态栏
status=htk.StatusBar(root) #建立状态栏
status.pack(side=tk.BOTTOM, fill=tk.X)
status.clear() #清空状态栏信息
status.text(0,'状态栏') #在状态栏0输出信息
status.text(1,'超越自我!') #在状态栏2输出信息
status.text(2,'人生苦短,学习中文Pyhthon3 !') #在状态栏2输出信息
status.text(3,'设计:独狼')
status.text(4,'版权所有!')
status.text(5,'侵权必究!')
status.config(1,color='red') #改变状态栏2信息颜色
status.config(0,color='blue') #改变状态栏0信息颜色
status.config(3,width=14) #改变状态栏3宽度
#分割窗口为左右两部分,m1左,m2右
m1 = tk.PanedWindow(root,showhandle=True, sashrelief=tk.SUNKEN,sashwidth=1,width=200) #默认是左右分布的
m1.pack(fill=tk.BOTH, expand=1)
m2 = tk.PanedWindow(orient=tk.VERTICAL, showhandle=True, sashrelief=tk.SUNKEN,height=500)
m1.add(m2)
#t2是右上画面
t2=tk.Frame(m2,bg='blue',heigh=500)
m2.add(t2)
ucode=htk.useredit(t2,fontsize=12) #代码编辑框
ucode.fontsize=12
m2.paneconfig(t2,heigh=500)
#T3是右下画面
t3=tk.Frame(m2,bg='yellow',heigh=150)
m2.add(t3)
umess=htk.useredit2(t3,fontsize=12) #信息输出框
m2.paneconfig(t3,heigh=3150)
htk.ttmsg=umess.textPad #绑定信息输出变量,
ucode.outmess=htk.ttmsg #设置代码输出信息框
label3 = tk.Label(umess.statusbar ,width=5, text='AI对话:')
label3.pack(side=tk.LEFT)
us=tk.StringVar(value='')
us2=tk.Entry(umess.statusbar,width=110, textvariable=us)
us2.pack(side=tk.LEFT)
path='./guide'
ucode.loadfile(path+'/软件说明.txt')
global timer
def fun_timer2():
global timer
def fun_timer():
global timer
dt=time.strftime(' %Y-%m-%d %H:%M:%S',time.localtime(time.time()))
status.text(1,dt) #在状态栏2输出信息
timer = threading.Timer(1, fun_timer)
timer.start()
timer = threading.Timer(1, fun_timer)
timer.start()
htk.thread_it(fun_timer2())
def udestroy():
global timer
timer.cancel()
root.udestroy=udestroy
root.mainloop() #开启tk主循环
程序运行结果如下:
上面给出的是部分演示代码,如果继续深入开发,完全可以实现IDEL编辑器的功能.
上面的Python代码编辑器模块,我们已经用在商业化的小白量化软件中了.
来源:https://blog.csdn.net/hepu8/article/details/108035456
0
投稿
猜你喜欢
- 如下所示:#!/usr/bin/env python# -*- coding:utf-8 -*-import datetimetime_de
- 1、登录SMTP服务器首先使用网上的方法(这里使用163邮箱,smtp.163.com是smtp服务器地址,25为端口号):import s
- 在 MySQL 中通常我们使用 limit 来完成页面上的分页功能,但是当数据量达到一个很大的值之后,越往后翻页,接口的响应速度就越慢。本文
- 1.python实现对doc文档的读取#读取docx中的文本代码示例import docx#获取文档对象file=docx.Document
- 本书的作者Douglas Crockford是JavaScript开发社区最知名的权威,JavaScript的发明人Brendan Eich
- pygame.transform 模块允许您对加载、创建后的图像进行一系列操作,比如调整图像大小、旋转图片等操作,常用方法如下所示:下面看一
- 〇、前言文件上传/下载接口与普通接口类似,但是有细微的区别。如果需要发送文件到服务器,例如:上传文档、图片、视频等,就需要发送二进制数据,上
- 自动上次ymPrompt组件发布,自己就曾发现在IE8下遮罩的半透明滤镜有时无效的问题,后来也有网友提出过这个问题,但自己一直也没有太多关注
- python中自定义模块导入路径的方式主要有以下3种:(1)使用sys.path.append()随着程序执行,会动态地添加模块导入的路径,
- atan()方法返回x的反正切值,以弧度表示。Syntax以下是atan()方法的语法:atan(x)注意:此函数是无法直接访问
- python的版本及依赖的库的安装#版本python 3.7.1pip install pywin32==224pip install nu
- 功能很简单,代码也很简洁,这里就不多废话了。package mainimport ( "fmt
- 如下所示:torch.mm(mat1, mat2, out=None) → Tensortorch.matmul(mat1, mat2, o
- Anaconda 本质上是一个软件发行版,包含了 conda、Python 等 180 多个科学包及其依赖项。因为包含了大量的科学包,Ana
- 生产者代码:# -* coding:utf8 *- from pykafka import KafkaClient host = '
- 问题联邦学习原始论文中给出的FedAvg的算法框架为:参数介绍: K 表示客户端的个数, B表示每一次本地更新时的数据量, E 表示本地更新
- 捣鼓了一天一直报错:Error running ‘mypython': Can't run remote python in
- 本文实例讲述了python迭代器的简单用法,分享给大家供大家参考。具体分析如下:生成器表达式是用来生成函数调用时序列参数的一种迭代器写法生成
- PTB数据集内容如下:一行保存一个句子;将稀有单词替换成特殊字符 < unk > ;将具体的数字替换 成“N
- 我在代码里定义了两个通道,分别用于生产端口和限制连接数,如果不限制连接数,容易被对方检测到或导致对方服务器不能正常运行。// 生产端口var