av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

python 實現簡易的記事本

瀏覽:98日期:2022-07-03 17:07:52

運行效果

python 實現簡易的記事本

完整代碼

from tkinter import *from tkinter.filedialog import *from tkinter.messagebox import *import osfilename=’’def author(): showinfo(’大道至簡’,’簡易記事本第一版’)def power(): showinfo(’版權信息’,’本公司保留版權信息,不可以把本軟件用于商業目的!’)def myopen(): global filename filename=askopenfilename(defaultextension=’.txt’) if filename==’’: filename=None else: root.title(’簡易記事本’+os.path.basename(filename)) textPad.delete(1.0,END) f=open(filename,’r’) textPad.insert(1.0,f.read()) f.close()def new(): global root,filename,textPad root.title(’未命名文件’) filename=None textPad.delete(1.0,END)def save(): global filename try: f=open(filename,’w’) msg=textPad.get(1.0,’end’) f.write(msg) f.close() except: saveas()def saveas(): f=asksaveasfile(initialfile=’未命名.txt’,defaultextension=’.txt’) global filename filename=f fh=open(f,’w’) msg=textPad.get(1.0,END) fh.write(msg) fh.close() root.title(’簡易記事本’+os.path.basename(f))def cut(): global textPad textPad.event_generate(’<<Cut>>’)def copy(): global textPad textPad.event_generate(’<<Copy>>’)def paste(): global textPad textPad.event_generate(’<<Paste>>’)def undo(): global textPad textPad.event_generate(’<<Undo>>’)def redo(): global textPad textPad.event_generate(’<<Redo>>’)def select_all(): global textPad textPad.tag_add(’sel’,’1.0’,’end’)def find(): global root t=Toplevel(root) t.title(’查找’) t.geometry(’260x60+200+250’) t.transient(root) Label(t,text=’查找:’).grid(row=0,column=0,sticky=’e’) v=StringVar() e=Entry(t,width=20,textvariable=v) e.grid(row=0,column=1,padx=2,pady=2,sticky=’we’) e.focus_set() c=IntVar() Checkbutton(t,text=’不區分大小寫’,variabel=c).grid(row=1,column=1,sticky=’e’) Button(t,text=’查找所有’,command=lambda :search(v.get(),c.get(),textPad,t,e)).grid(row=0, column=2,sticky=’e’+’w’,padx=2,pady=2)def close_search(): textPad.tag_remove(’match’,’1.0’,END) t.destroy() t.protocol(’WM_DELETE_WINDOW’,close_search)#???def search(needle,cssnstv,textPad,t,e): textPad.tag_remove(’match’,’1.0’,END) count=0 if needle: pos=’1.0’ while True: pos=textPad.search(needle,pos,nocase=cssnstv,stopindex=END) if not pos:break lastpos=pos+str(len(needle)) textPad.tag_add(’match’,pos,lastpos) count+=1 pos=lastpos textPad.tag_config(’match’,foreground=’yellow’,background=’green’) e.focus_set() t.title(str(count)+’個被匹配’)def popup(event): global editmenu editmenu.tk_popup(event.x_root,event.y_root)root=Tk()root.title(’簡易記事本第一版’)root.geometry(’300x300+100+100’)#geometry(wxh+xoffset+yoffset)menubar=Menu(root)#制作菜單實例,依附于父窗口root上面filemenu=Menu(menubar)#制作文件菜單項,依附于menubar菜單上面menubar.add_cascade(label=’文件’,menu=filemenu)#增加分層菜單filemenu.add_command(label=’新建’,accelerator=’Ctrl+N’,command=new)filemenu.add_command(label=’打開’,accelerator=’Ctrl+O’,command=myopen)filemenu.add_command(label=’保存’,accelerator=’Ctrl+S’,command=save)filemenu.add_command(label=’另存為’,accelerator=’Ctrl+Alt+S’,command=saveas)editmenu=Menu(menubar)#制作編輯菜單項,依附于menubar菜單上面menubar.add_cascade(label=’編輯’,menu=editmenu)editmenu.add_command(label=’撤銷’,accelerator=’Ctrl+Z’,command=undo)editmenu.add_command(label=’重做’,accelerator=’Ctrl+Y’,command=redo)editmenu.add_command(label=’剪切’,accelerator=’Ctrl+X’,command=cut)editmenu.add_command(label=’復制’,accelerator=’Ctrl+C’,command=copy)editmenu.add_command(label=’粘貼’,accelerator=’Ctrl+V’,command=paste)editmenu.add_separator()editmenu.add_command(label=’查找’,accelerator=’Ctrl+F’,command=find)editmenu.add_command(label=’全選’,accelerator=’Ctrl+A’,command=select_all)aboutmenu=Menu(menubar)#制作關于菜單項,依附于menubar菜單上面menubar.add_cascade(label=’關于’,menu=aboutmenu)#增加分層菜單aboutmenu.add_command(label=’作者’,command=author)aboutmenu.add_command(label=’版權’,command=power)root.config(menu=menubar)shortcutbar=Frame(root,height=25,bg=’light sea green’)shortcutbar.pack(expand=NO,fill=X)Inlabel=Label(root,width=2,bg=’antique white’)Inlabel.pack(side=LEFT,anchor=’nw’,fill=Y)textPad=Text(root,undo=True)textPad.pack(expand=YES,fill=BOTH)scroll=Scrollbar(textPad)textPad.config(yscrollcommand=scroll.set)scroll.config(command=textPad.yview)scroll.pack(side=RIGHT,fill=Y)textPad.bind(’<Control-N>’,new)textPad.bind(’<Control-n>’,new)textPad.bind(’<Control-O>’,myopen)textPad.bind(’<Control-o>’,myopen)textPad.bind(’<Control-S>’,save)textPad.bind(’<Control-s>’,save)textPad.bind(’<Control-A>’,select_all)textPad.bind(’<Control-a>’,select_all)textPad.bind(’<Control-f>’,find)textPad.bind(’<Control-F>’,find)textPad.bind(’<Control-3>’,popup)root.mainloop()

以上就是python 實現簡易的記事本的詳細內容,更多關于python 實現記事本的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: а天堂中文最新一区二区三区 | 久久久久久成人 | 一区二区三区视频在线观看 | 天天躁日日躁狠狠很躁 | 精品一级 | 久草视频网站 | 男女在线免费观看 | 亚洲一区二区三区四区视频 | 香蕉一区二区 | 美女三区| 99re在线| 在线观看中文字幕dvd播放 | 国产一区 在线视频 | 中文字幕第7页 | 亚州国产 | 国产精品不卡 | 中文av在线播放 | 日韩男人天堂 | 午夜寂寞福利视频 | 久久99精品久久久久久国产越南 | 欧美日韩高清在线一区 | 亚洲v日韩v综合v精品v | av免费网站在线观看 | 国产一区二区高清在线 | 日韩成人影院 | 夜夜爽99久久国产综合精品女不卡 | 欧美视频精品 | 亚洲欧洲日本国产 | 老外黄色一级片 | 激情网站| 天天操天天天干 | 亚洲精品一区在线 | 91精品久久久久久久久 | 国产精品电影在线观看 | 国产小视频在线 | 欧美视频一区二区三区 | 日日操夜夜操视频 | 日韩不卡在线观看 | 国产在线视频一区二区董小宛性色 | 天堂免费看片 | 国产精品久久久久久久久久久久 |