Quotidien Shaarli

Tous les liens d'un jour sur une page.

November 7, 2017

code pour génération html

#permet de générer un code html pour publication de snyppet pyton

import tkinter

main_window = tkinter.Tk() # on lance la fenetre tkinter

label_titre = tkinter.Label(main_window, text='Titre du code')
label_titre.grid()

titre = tkinter.Text(main_window,height=2, width = 120)
titre.grid()

label_code= tkinter.Label(main_window, text='Code')
label_code.grid()

code = tkinter.Text(main_window,height=12, width = 120)
code.grid()

def generer():
balise_html.delete('1.0', tkinter.END)
balise_html.insert(tkinter.END,'<a href="#' + titre.get( '1.0', tkinter.END).replace(' ','').replace('\n','') + '">' + titre.get( '1.0', tkinter.END).replace('\n','')+'</a><br>')

code_html.delete('1.0', tkinter.END)
code_html.insert(tkinter.END,'<p><div id="' + titre.get( '1.0', tkinter.END).replace(' ','').replace('\n','') + '"></div>'+'\n')
code_html.insert(tkinter.END,'<b>' + titre.get( '1.0', tkinter.END).replace('\n','') + '<br></b>'+'\n')
code_html.insert(tkinter.END,code.get( '1.0', tkinter.END).replace('    ','&nbsp;&nbsp;&nbsp;&nbsp;').replace('\n','<br>'+'\n')+'</p>')

button_generer = tkinter.Button(main_window,text=u"Générer code", command=generer, bg='LightSkyBlue1')
button_generer.grid ()

label_balise = tkinter.Label(main_window, text='Ancre html a placer en début de fichier')
label_balise.grid()

balise_html = tkinter.Text(main_window,height=2, width = 120)
balise_html.grid()

label_html = tkinter.Label(main_window, text='Code html a placer dans le corps du fichier')
label_html.grid()

code_html = tkinter.Text(main_window,height=12, width = 120)
code_html.grid()

main_window.mainloop()
input()