最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python用Tkinter做自己的中文代碼編輯器

 更新時(shí)間:2020年09月07日 11:04:20   作者:荷蒲  
這篇文章主要介紹了python用Tkinter做自己的中文代碼編輯器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前面我們給了Tkinter接管Python輸入和輸出的介紹,我們不難可以想到,能用Tkinter來(lái)開(kāi)發(fā)自己的Python代碼編輯器.例如可以使用Text控件作代碼編輯器.

實(shí)際上我在HP_tk2中已經(jīng)封裝好了現(xiàn)成的中文Python代碼編輯器組件和防Ipython功能的組件,另用這2個(gè)組件很容易搭建出自己的代碼編輯器.

下面直接給出完整演示源代碼.

#中文可視化Python開(kāi)發(fā)系統(tǒng).py
import tkinter as tk #導(dǎo)入Tkinter
import tkinter.ttk as ttk #導(dǎo)入Tkinter.ttk
import tkinter.tix as tix #導(dǎo)入Tkinter.tix
from tkinter.filedialog import *
from tkinter.messagebox import *
import PIL
from PIL import Image, ImageTk, ImageDraw, ImageFont
import HP_tk2 as htk #導(dǎo)入htk
import webbrowser
import os
import sys
import threading
import time


#建立應(yīng)用窗口
root=htk.MainWindow(title='中文Python代碼編輯器',x=0,y=0,w=1200, h=800,picture='',zoom=True,center=True)
root.iconbitmap('ico/cp64.ico') #設(shè)置應(yīng)用程序圖標(biāo)
root.SetCenter() #移動(dòng)到屏幕中央


#建立菜單
menus = [['文件',['執(zhí)行程序','-','新建','打開(kāi)','運(yùn)行','-','保存','另存為']],\
   ['編輯',['撤銷(xiāo)','重做','-','剪切','復(fù)制','粘貼','清除','-','全選']],\
   ['顯示',['繪圖','表格']],\
   ['程序',['運(yùn)行','編譯']],\
   ['項(xiàng)目',['工程設(shè)置','系統(tǒng)設(shè)置']],\
   ['數(shù)據(jù)',['連接行情服務(wù)器','斷開(kāi)行情服務(wù)器','下載股票代碼表','下載財(cái)務(wù)數(shù)據(jù)',\
    '下載板塊數(shù)據(jù)']],\
   ['幫助',['關(guān)于軟件','退出']]]
   
mainmenu=htk.windowMenu(root,menus) #窗口菜單


toolsbar=htk.ToolsBar(root,6,bg='yellow') #創(chuàng)建工具欄,參數(shù)1-20
toolsbar.pack(side=tk.TOP, fill=tk.X)

#改變工具條圖標(biāo)
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)


#創(chuàng)建狀態(tài)欄
status=htk.StatusBar(root) #建立狀態(tài)欄
status.pack(side=tk.BOTTOM, fill=tk.X)
status.clear() #清空狀態(tài)欄信息
status.text(0,'狀態(tài)欄') #在狀態(tài)欄0輸出信息
status.text(1,'超越自我!') #在狀態(tài)欄2輸出信息
status.text(2,'人生苦短,學(xué)習(xí)中文Pyhthon3 !') #在狀態(tài)欄2輸出信息
status.text(3,'設(shè)計(jì):獨(dú)狼')
status.text(4,'版權(quán)所有!')
status.text(5,'侵權(quán)必究!')
status.config(1,color='red') #改變狀態(tài)欄2信息顏色
status.config(0,color='blue') #改變狀態(tài)欄0信息顏色
status.config(3,width=14) #改變狀態(tài)欄3寬度
#分割窗口為左右兩部分,m1左,m2右
m1 = tk.PanedWindow(root,showhandle=True, sashrelief=tk.SUNKEN,sashwidth=1,width=200) #默認(rèn)是左右分布的
m1.pack(fill=tk.BOTH, expand=1)

m2 = tk.PanedWindow(orient=tk.VERTICAL, showhandle=True, sashrelief=tk.SUNKEN,height=500)
m1.add(m2)
#t2是右上畫(huà)面
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是右下畫(huà)面
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 #設(shè)置代碼輸出信息框
label3 = tk.Label(umess.statusbar ,width=5, text='AI對(duì)話:')
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+'/軟件說(shuō)明.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) #在狀態(tài)欄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() #開(kāi)啟tk主循環(huán)

程序運(yùn)行結(jié)果如下:


上面給出的是部分演示代碼,如果繼續(xù)深入開(kāi)發(fā),完全可以實(shí)現(xiàn)IDEL編輯器的功能.

上面的Python代碼編輯器模塊,我們已經(jīng)用在商業(yè)化的小白量化軟件中了.

到此這篇關(guān)于python用Tkinter做自己的中文代碼編輯器的文章就介紹到這了,更多相關(guān)Tkinter 中文代碼編輯器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

福建省| 长宁县| 肇庆市| 揭阳市| 彭阳县| 襄城县| 道孚县| 崇信县| 全州县| 昆山市| 永寿县| 木里| 老河口市| 册亨县| 聂荣县| 洛扎县| 营口市| 当涂县| 金寨县| 神池县| 鄄城县| 康乐县| 吐鲁番市| 沂南县| 浏阳市| 云南省| 商都县| 桦南县| 儋州市| 曲松县| 固安县| 永济市| 赤峰市| 琼中| 仙居县| 吉首市| 泰来县| 永清县| 托里县| 普陀区| 绥阳县|