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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| from tkinter import *
root = Tk() root.title("url-md") root.config(bg='#FFEDDF') root.iconbitmap("hhh.ico")
def mwindow(): screenWidth = root.winfo_screenwidth() screenHeight = root.winfo_screenheight() w = 300 h = 160 x = (screenWidth - w) / 2 y = (screenHeight - h) / 2 root.geometry("%dx%d+%d+%d" % (w, h, x, y))
def windowset(): label = Label(root, text="前缀", fg="black", bg="#FFEDDF") label.pack(anchor=N, side=LEFT, padx=10, pady=10) label = Label(root, text="后缀", fg="black", bg="#FFEDDF") label.pack(anchor=N, side=LEFT, padx=50, pady=10) label = Label(root, text="自动序号", fg="black", bg="#FFEDDF") label.pack(anchor=N, side=LEFT, padx=0, pady=10) label = Label(root, text="-wxy", fg="blue", bg="#FFEDDF") label.pack(side=BOTTOM, padx=10, pady=10) btn = Button(root, padx=0, pady=0, bd=2,relief=GROOVE, bg="white", text="转换", command=get_url) btn.place(x=130, y=120) global former, latter, main,var former = Entry(root,width=6,bd=2,relief=GROOVE) latter = Entry(root,width=6,bd=2,relief=GROOVE) main = Text(root,width=6,bd=2,relief=GROOVE) former.place(x=45,y=10) latter.place(x=133, y=10) main.place(x=50,y=40,width=200,height=60) var =IntVar() select = Checkbutton(root,bg="#FFEDDF",variable=var) select.place(x=230,y=8) root.mainloop()
def get_url(): urlformer = former.get() urllatter = latter.get() url = main.get(1.0,END) if url[-2] == '\n': url = url[0:-1]
md = '' if var.get() == 0: md = urlformer + url.replace('\n', urllatter + '\n' + urlformer) l = len(urlformer) main.delete(1.0, END) main.insert(END, md[0:-l]) else: md = urlformer + url.replace('\n', urllatter + '\n' + urlformer) ran = md.count('$') for i in range(ran): md = md.replace('$',str(i),1) l = len(urlformer) main.delete(1.0, END) main.insert(END, md[0:-l])
mwindow() windowset()
|