python_为html方便地加yaml_title

 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
import time
from tkinter import *
import tkinter as tk
from tkinter import filedialog
from xml.etree.ElementTree import tostring
import shutil 


#文件设置函数:获得填入的·值,然后以txt打开html文件,将值插入到第一行。顺手将文件移动到source文件下
def settitle():
    print(E1.get(),1)  
    charu = E1.get() 
    with open(filename, 'r+',encoding= "utf-8") as f:
        content = f.read()        
        f.seek(0, 0)
        f.write('---\n'+'title:'+charu+time.ctime(time.time()) +'\n---\n'+content)
    shutil.move(filename,filesasve)
    top.destroy()
    return charu

# 使用tkinter写个简单的界面
charu = "标题"
top = tk.Tk()

top.title('set-title') 
top.wm_geometry("300x80+488-375")

L1 = tk.Label(master=top, text="title:",).grid(row=0, column=0)
E1 = tk.Entry(top, bd =5,width=32)
E1.grid(row=0, column=1)
btn1 = tk.Button(top,text='保存👀',command=settitle).grid(row=1, column=1,)

filename = filedialog.askopenfilename()
filesasve = "D:/recent_project\mmnotes\hnote\source\_posts"


print(E1.get())   
top.mainloop()
CTRL-/