Im confused and I need to know how to read from a tkinter textbox in order to create a text editor. Also would it be possible to have certain words colorized as you type in words? I would like to make this into a code editor possibly. Any help would be greatly apreciated.

from Tkinter import *
import tkMessageBox
import EasyDialogs #a windows port of the mac module
import sys
def Exit():
    sys.exit()
def Help():
    tkMessageBox.showinfo("Help","Created by Erik Anderson")
def ask_save():
    response = tkMessageBox.askyesno("Save?", "Would you like to save?")
    if response == True:
        File = EasyDialogs.AskFileForSave("Save File")
####################################
        text = #This Is where i need the function
####################################
        Filesave = open(File, 'w')
        Filesave.write(text)
        Filesave.close()
    elif response == False:
        pass
def new():
    ask_save()
root = Tk()
menu = Menu(root)
text = Text(root)
root.config(menu=menu)

filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=new)
filemenu.add_command(label="Open...", command=new)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=Exit)

helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=Help)

Textbox = Text(root)
Textbox.pack(side=LEFT)

root.mainloop()

thx in advance!
Erik Anderson

To colorize words you are asking too much of good old Tkinter. You most likely need to got with the wx.StyledTextCtrl() widget.
This STC control wraps the Scintilla editor component so it will work with wxPython. Could be that something like this is available for Tlinter.

If it's an entry box...

entry = Entry()
entry.pack()
##### Type 'hello' into the box
print entry.get()
>> hello

Looking through IDLE's source code (should be right on your drive) might give you some insight into code highlighting.

To colorize words you are asking too much of good old Tkinter. You most likely need to got with the wx.StyledTextCtrl() widget.
This STC control wraps the Scintilla editor component so it will work with wxPython. Could be that something like this is available for Tlinter.

How about IDLE, that's written using the Tkinter GUI toolkit.

Had this in my Tkinter code examples ...

# multiple color text with Tkinter

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()
root.geometry("600x400")

text_widget = tk.Text(root)
text_widget.pack()

x = ["hello", "world"]

# insert "hello" in blue
text_widget.insert(tk.END, x[0])
end_index = text_widget.index(tk.END)
begin_index = "%s-%sc" % (end_index, len(x[0]) + 1)
text_widget.tag_add("blue", begin_index, end_index)
text_widget.tag_config("blue", foreground='blue')

# insert "world" in red
text_widget.insert(tk.END, x[1])
end_index = text_widget.index(tk.END)
begin_index = "%s-%sc" % (end_index, len(x[1]) + 1)
text_widget.tag_add("red", begin_index, end_index)
text_widget.tag_config("red", foreground='red')

root.mainloop()
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.