Example #1
0
class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.myfont = font.Font(family='Helvetica', size=14)
        self.init_window()

    def init_window(self):
        self.master.title("Markdown 编辑器")
        self.pack(fill=BOTH, expand=1)

        self.inputeditor = Text(self, width="1", font=self.myfont)
        self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT)

        self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Markdown 编辑器</h1>")
        self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
        self.outputbox.fit_height()

        self.inputeditor.bind("<<Modified>>", self.onInputChange)

        self.mainmenu = Menu(self)
        self.filemenu = Menu(self.mainmenu)
        self.filemenu.add_command(label="打开", command=self.openfile)
        self.filemenu.add_command(label="另存为", command=self.savefile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="退出", command=self.quit)
        self.mainmenu.add_cascade(label="文件", menu=self.filemenu)
        self.master.config(menu=self.mainmenu)

    def onInputChange(self, event):
        self.inputeditor.edit_modified(0)
        md2html = Markdown()
        self.outputbox.set_html(md2html.convert(self.inputeditor.get('1.0', END)))

    def openfile(self):
        openfilename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *mdown , *.markdown"),
                                                             ("Text File", "*.txt"),
                                                             ("All Files", "*.*")))
        if openfilename:
            try:
                self.inputeditor.delete(1.0, END)
                self.inputeditor.insert(END, open(openfilename, encoding='utf-8').read())
            except Exception as e:
                mbox.showerror(f"无法打开文件({openfilename})!Error:{e}")

    def savefile(self):
        filedata = self.inputeditor.get("1.0", END)
        savefilename = filedialog.asksaveasfilename(filetypes=(("Markdown File", "*.md"),
                                                              ("Text File", "*.txt")),
                                                    title="保存Markdown 文件")
        if savefilename:
            try:
                with open(savefilename, 'w', encoding='utf-8') as f:
                    f.write(filedata)
            except Exception as e:
                mbox.showerror("保存文件错误", f"文件{savefilename}保存错误!ERROR: {e}")


    def quit(self):
        self.master.quit()
Example #2
0
class MDText(Frame):
    def __init__(self, master, **kwargs):
        Frame.__init__(self, master, **kwargs)
        self.master = master
        self.myfont = font.Font(family="Helvetica", size=14)
        self.init_window()

    def init_window(self):
        self.pack(fill=BOTH, expand=1)
        self.inputeditor = Text(self, width="1", font=self.myfont, bg='black', insertbackground='white', fg='white',
                                wrap=WORD)
        self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT)
        self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Welcome</h1>")
        self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
        self.outputbox.fit_height()
        self.inputeditor.bind("<<Modified>>", self.onInputChange)
        self.mainmenu = Menu(self.master.master)
        self.filemenu = Menu(self.mainmenu)
        self.filemenu.add_command(label="Open", command=self.openfile)
        self.filemenu.add_command(label="Save as", command=self.savefile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit", command=self.quit)
        self.mainmenu.add_cascade(label="File", menu=self.filemenu)
        self.master.master.config(menu=self.mainmenu)

    def onInputChange(self, event):
        self.inputeditor.edit_modified(0)
        md2html = Markdown()
        # self.outputbox.set_html(md2html.convert(self.inputeditor.get("1.0" , END)))
        markdownText = self.inputeditor.get("1.0", END)
        html = md2html.convert(markdownText)
        self.outputbox.set_html(html)

    def openfile(self):
        openfilename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *.mdown , *.markdown"),
                                                            ("Text File", "*.txt"),
                                                            ("All Files", "*.*")))
        if openfilename:
            try:
                self.inputeditor.delete(1.0, END)
                self.inputeditor.insert(END, open(openfilename).read())
            except:
                # print("Cannot Open File!")
                mbox.showerror("Error Opening Selected File" , "Oops!, The file you selected : {} can not be opened!".format(openfilename))
    
    def savefile(self):
        filedata = self.inputeditor.get("1.0" , END)
        savefilename = filedialog.asksaveasfilename(filetypes = (("Markdown File", "*.md"), ("Text File", "*.txt")),
                                                    title="Save Markdown File")
        if savefilename:
            try:
                f = open(savefilename, "w")
                f.write(filedata)
            except:
                mbox.showerror("Error Saving File", "Oops!, The File : {} can not be saved!".format(savefilename))
Example #3
0
def main_func():
    global start, lbl3, country, textExample, countryCode_button, html_label
    lbl2.destroy()
    countries.destroy()
    lbl3 = Label(
        root,
        text="-------------"
        "--                                                 ---------------"
        "--\n    'The future is ours to shape.\n I feel we"
        "are in a race that we need to win.\n It’s a race between the growing"
        " power\nof the technology and the growing\n wisdom"
        " we need to manage it.'\n                                  "
        "   ~Max Tegmark"
        "                    \n---------------                               "
        "                  -----------------",
        bg="black",
        fg="white",
        font="Times 18",
        pady=10)
    lbl3.config(anchor=CENTER)
    lbl3.pack(pady=10)
    start.destroy()
    country = Label(root,
                    text='Enter the country code to setup the alerts',
                    bg="black",
                    fg="white",
                    font="Times 18",
                    pady=10)
    country.pack(side=TOP, pady=10)
    textExample = Text(root, height=1, width=12)
    textExample.pack(side=TOP, pady=5)
    countryCode_button = Button(root, text="Enter", command=retrieve_input)
    countryCode_button.pack(side=TOP, pady=10)
    html_label = HTMLLabel(root,
                           html='<a href="https://blockchain.info/ticker"'
                           'style="color: green; text-align: center"> '
                           ' Please visit:- https://blockchain.info/ticker,  '
                           ' to know all the listed countries </a>')
    # html_label.pack(fill="both", expand=True)
    html_label.pack()
    html_label.fit_height()
class Window(tk.Frame):

    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.master = master
        self.font = font.Font(family='Helvetica', size=14)
        self.init_window()

    def openfile(self):
        filename = \
            filedialog.askopenfilename(filetypes=(('Markdown File',
                                                   '*.md , *.mdown'),
                                                  ('Text file', '*.txt')))
        if filename:
            try:
                md2html = Markdown()
                self.outputbox.set_html(md2html.convert(open(filename,
                                                             'r').read()))
            except Exception:
                mbox.showerror('Error opening file',
                               'The selected file cannot be opened !')

    def init_window(self):
        self.master.title('Mardown Viewer')
        self.pack(fill=tk.BOTH, expand=1)

        self.mainmenu = tk.Menu(self)
        self.filemenu = tk.Menu(self.mainmenu)
        self.filemenu.add_command(label='Open', command=self.openfile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label='Exit', command=self.quit)
        self.mainmenu.add_cascade(label='File', menu=self.filemenu)
        self.master.config(menu=self.mainmenu)

        self.outputbox = HTMLLabel(self, width='1', background='white',
                                   html='<h1>Welcome</h1>')
        self.outputbox.pack(fill=tk.BOTH, expand=1, side=tk.RIGHT)
        self.outputbox.fit_height()
Example #5
0
Button(quickmenu, text="斜体", command=unc, width=6, height=3).place(x=300, y=50)
Button(quickmenu, text="引用", command=userfrom, width=6, height=3).place(x=360,
                                                                        y=50)
Button(quickmenu, text="图片", command=pic, width=6, height=3).place(x=420, y=50)
Button(quickmenu, text="超链接", command=superlink, width=6,
       height=3).place(x=480, y=50)

tools.place(x=0, y=0)


def onInputChange(event):
    inputeditor.edit_modified(0)
    md2html = Markdown()
    outputbox.set_html(md2html.convert(inputeditor.get("1.0", END)))


inputeditor = Text(showbar, height=70, width=60)
#inputeditor.pack(fill=BOTH, expand=1, side=LEFT)
inputeditor.pack(side=LEFT, fill=BOTH)
outputbox = HTMLLabel(showbar,
                      background="white",
                      html="<h1>这里什么也没有写</h1>",
                      height=600,
                      width=55)
outputbox.pack(side=RIGHT, fill=BOTH)
inputeditor.bind("<<Modified>>", onInputChange)
#outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
outputbox.fit_height()
#Button(showbar).place(x=0,y=0)\

root.mainloop()
import tkinter as tk
from tkhtmlview import HTMLLabel

root = tk.Tk()
root.title("Test Html on Tkinter")
root.configure(bg='black')

data = """<!-- Dynamic Coding output code  -->
<p style="border: 2px solid rgb(51, 103, 214); font-size: 15px; padding: 0.2em 0.6em;"><font face="arial">
<kbd style="border-radius: 0px; border: 1px solid rgb(51, 103, 214); padding: 3px;color:#3367d6;"><b>&nbsp;  Output &nbsp;</b></kbd>
<br />
<code style="color:#ff0000">
deque(['A', 'B', 'C', 'D'])


</code>
</font></p>
<br />


"""
html_label = HTMLLabel(root, html=data)
html_label.pack(fill="both", expand=True)
html_label.fit_height()
root.mainloop()
class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.myfont = font.Font(family="Helvetica", size=14)
        self.init_window()

    # On Input Change
    def onInputChange(self, event):
        self.inputeditor.edit_modified(0)
        md2html = Markdown()
        markdownText = self.inputeditor.get("1.0", END)
        html = md2html.convert(markdownText)
        self.outputbox.set_html(html)

    # Function to save File
    def savefile(self, event):
        filedata = self.inputeditor.get("1.0", END)
        savefilename = filedialog.asksaveasfilename(
            filetypes=(("Markdown File", "*.md"), ("Text File", "*.txt")),
            title="Save Markdown File")
        if savefilename:
            try:
                f = open(savefilename, "w")
                f.write(filedata)
            except:
                mbox.showerror(
                    "Error Saving File",
                    "Oops!, The File : {} can not be saved!".format(
                        savefilename))

    # FUnction to open file
    def openfile(self, event):
        openfilename = filedialog.askopenfilename(
            filetypes=(("Markdown File", "*.md , *.mdown , *.markdown"),
                       ("Text File", "*.txt"), ("All Files", "*.*")))
        if openfilename:
            try:
                self.inputeditor.delete(1.0, END)
                self.inputeditor.insert(END, open(openfilename).read())
            except:
                mbox.showerror(
                    "Error Opening Selected File",
                    "Oops!, The file you selected : {} can not be opened!".
                    format(openfilename))

    def md2html(self):
        filedata = markdown.markdown(self.inputeditor.get("1.0", END))
        savefilename = filedialog.asksaveasfilename(
            filetypes=(("HTML File", "*.html"), ("Text File", "*.txt")),
            title="Save HTML File")

        if savefilename:
            try:
                f = open(savefilename, "w")
                f.write(filedata)
            except:
                mbox.showerror(
                    "Error Saving File",
                    "Oops!, The File : {} can not be saved!".format(
                        savefilename))

    def saveonly(self, event):
        filedata = markdown.markdown(self.inputeditor.get("1.0", END))

    def init_window(self):
        self.master.title("MDitor")
        self.pack(fill=BOTH, expand=1)

        self.inputeditor = Text(self, width="1")
        self.inputeditor = Text(self, width="1", font=self.myfont)
        self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT)

        # For output window
        self.outputbox = HTMLLabel(self,
                                   width="1",
                                   background="lightgray",
                                   html="START TYPING TO SEE OUTPUT...")
        self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
        self.outputbox.fit_height()

        # change output as we type
        self.inputeditor.bind("<<Modified>>", self.onInputChange)
        # ctrl-s shortcut
        self.inputeditor.bind('<Control-s>', self.savefile)
        # ctrl-o shortcut
        self.inputeditor.bind('<Control-o>', self.openfile)
        # ctrl-h shortcut
        self.inputeditor.bind('<Control-h>', self.md2html)

        # File and Open
        self.mainmenu = Menu(self)
        self.filemenu = Menu(self.mainmenu)
        self.filemenu.add_command(label="Open", command=self.openfile)
        self.filemenu.add_command(label="Save as", command=self.savefile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit", command=self.quit)
        self.mainmenu.add_cascade(label="File", menu=self.filemenu)
        self.mainmenu.add_cascade(label="Save HTML", command=self.md2html)
        self.master.config(menu=self.mainmenu)