Friday, July 24, 2015

Web Safe Code Cleaner In Python

This is a simple Python 3 script that I wrote to strip out the symbols that cause the web browsers to go crazy when you are trying to display your code.


 from tkinter import *
 from tkinter import ttk


 # Create the event handler first
 def btnConvert_Click():
    temp = tbSource.get('1.0', 'end')
    temp = temp.replace('<','<')
    temp = temp.replace('>','>')
    tbOutput.insert('1.0',temp)

 def btnClear_Click():
  tbSource.delete('1.0','end')
  tbOutput.delete('1.0','end')


 # Create the top level window/frame
 top = Tk()
 top.title("Web Safe Code Converter 1.0.0")

 fra = ttk.Frame(top)
 fra.pack(expand="true")

 # Now the frame with the two text widgets
 fraEntry = ttk.Frame(fra, border=1)
 tbSource = Text(fraEntry, width=40, height=20)
 tbOutput = Text(fraEntry, width=40, height=20)
 fraEntry.pack(side="top", expand="true")
 tbSource.pack(side="left", expand="true")
 tbOutput.pack(side="right", expand="true")

 # Finally the frame with the buttons.
 fraButton = Frame(fra)
 btnConvert = ttk.Button(fraButton, text="Convert", command=btnConvert_Click)
 btnClear = ttk.Button(fraButton, text="Clear", command=btnClear_Click)
 btnConvert.pack(side="left", padx=5, pady=6)
 btnClear.pack(side="left", padx=5, pady=6)
 fraButton.pack(side="top", expand="true")

 # Run the event loop
 fra.mainloop()

No comments:

Post a Comment