Hi, Iam new in python (1/2year) and here is the thing:
I made a small text editor with tkinter and I want to generate web page from the text editor (from formated text). To web page generating I will use the HTMLgen module. So it must be created another python program, witch will generate the html page with the text witch is in text in tkinter.
But I realy dont know how to do this
I apologise for my english
Any ideas? I would be very very happy. thanks for anything

Maybe post up some code or give some better examples of what you want to do.

I made a small text editor witch is not finished yet.
The program I must create must do:

  1. be able to format text
  2. generate html code with the text
  3. the text in web page must look same as the text in text editor
  4. I must use the HTMLgen module

So the user will write some text, format it, and click on button, witch will generate the web page with the users formated text.
There is the code I have wrote:

# -*- coding: utf-8 -*-
from Tkinter import*
import tkFileDialog,tkColorChooser


def otevrit():
    cesta=tkFileDialog.askopenfilename(title=u"Otevřít...")
    if cesta:
        text.delete(1.0,END)
        soubor=file(cesta,'r')
        text.insert(END,soubor.read())
        soubor.close()
         

def ulozit():
     cesta=tkFileDialog.asksaveasfilename(title=u"Uložit jako...")
     if cesta:
           soubor=file(cesta,'w')
           soubor.write(text.get(1.0,END))
           soubor.close()


#def ukoncit():



def novy():
    text.delete(1.0,END)



def nastav_barvu():
    nic, rgb=tkColorChooser.askcolor()
    if rgb:
        text.tag_config(rgb, foreground=rgb)
    try:
        text.tag_add(rgb,SEL_FIRST,SEL_LAST)
    except TclError:
        pass


def levo():
    text.tag_config("l",justify="left")
    try:
        text.tag_add("l",SEL_FIRST,SEL_LAST)
    except TclError:
        pass
def stred():
    text.tag_config("c",justify="center")
    try:
        text.tag_add("c",SEL_FIRST,SEL_LAST)
    except TclError:
        pass
def pravo():
    text.tag_config("p",justify="right")
    try:
        text.tag_add("p",SEL_FIRST,SEL_LAST)
    except TclError:
        pass







okno=Tk()


lista=Frame(okno)
lista.pack(fill=X)
Button(lista, text="Nový",command=novy).pack(side=LEFT,fill=Y)
Button(lista, text="Ulož",command=ulozit).pack(side=LEFT,fill=Y)
Button(lista, text="Otevři",command=otevrit).pack(side=LEFT,fill=Y)
Button(lista, text="Barva",command=nastav_barvu).pack(side=LEFT,fill=Y)
Button(lista, text="levo",command=levo).pack(side=LEFT,fill=Y)
Button(lista, text="střed",command=stred).pack(side=LEFT,fill=Y)
Button(lista, text="pravo",command=pravo).pack(side=LEFT,fill=Y)


hlavniMenu = Menu(okno)
menuSoubor = Menu(hlavniMenu, tearoff=0)
menuSoubor.add_command(label="Nový soubor",command=novy)
menuSoubor.add_command(label="Otevřít",command=otevrit)
menuSoubor.add_command(label="Uložit",command=ulozit)
menuSoubor.add_command(label="Konec",command=okno.destroy)
hlavniMenu.add_cascade(label="Soubor", menu=menuSoubor)
okno.config(menu=hlavniMenu)


obal=Frame(okno)
obal.pack(fill=BOTH,expand=1)
posuvnikY=Scrollbar(obal)
posuvnikY.pack(side=RIGHT,fill=Y)
posuvnikX=Scrollbar(obal, orient=HORIZONTAL)
posuvnikX.pack(fill=X,side=BOTTOM)
text=Text(obal,yscrollcommand=posuvnikY.set,xscrollcommand=posuvnikX.set,wrap=NONE)
text.pack(fill=BOTH,expand=1)
text.focus_set()
posuvnikX["command"]=text.xview
posuvnikY["command"]=text.yview

Well if I was going to approach this problem I would probably have a menu for the formatting options. From there I would probably just have the HTMLgen writing the document in the background as the user typed his formatted text into the editor since you already know at that point exactly what type of formatting they are doing. For example if they choose to use a 14pt bold font for a header they could select these options in the tkinter application then based on what they chose HTMLgen would use the appropriate functions to the text they write with those options selected in your tkinter interface.

how can I edit the posts? Is there any edit buton or Im blind? :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.