1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| \ import tkinter import os from tkinter import filedialog
win_size='450x550' win = tkinter.Tk() win.geometry(win_size)
win.title('Markdown Editor V1.0 (hexo only)')
def processandsave(): contents = '---\ntitle:' + title.get('0.0','end') + 'tags:' + tags.get('0.0','end') + '---\n' + content.get('0.0','end') filename = filedialog.asksaveasfilename() if filename is not None: with open(file=filename,mode='w') as file: file.write(str(contents)) title.delete('0.0','end') tags.delete('0.0','end') content.delete('0.0','end')
def add_bash(): add_content=add_bash_text.get('0.0','end') add_content=add_content.rstrip() changing_content='```bash\n'+add_content+'\n```\n' content.insert('end',changing_content) add_bash_text.delete('0.0','end')
label1=tkinter.Label(text='标题',padx=10,pady=10) label1.grid(row=0,column=0)
title=tkinter.Text(width=40,height=2) title.grid(row=0,column=1,columnspan=2)
label2=tkinter.Label(text='标签',padx=5,pady=5) label2.grid(row=1,column=0)
tags=tkinter.Text(width=30,height=1) tags.grid(row=1,column=1)
label3=tkinter.Label(text='正文',padx=5,pady=5) label3.grid(row=2,column=0)
content=tkinter.Text(width=40,height=20) content.grid(row=2,column=1,rowspan=5)
add_bash_button=tkinter.Button(win,text='命令行',command=add_bash) add_bash_button.grid(row=9,column=0)
add_bash_text=tkinter.Text(width=40,height=5) add_bash_text.grid(row=9,column=1)
save_button=tkinter.Button(win,text='保存',command=processandsave) save_button.grid(row=8,column=1)
win.mainloop()
|