Python - Reading line by line from file to Tkinter Text
<p>I decided I want to do some GUI programming with Python Tkinter,and I wanted to start with a Text Editor.I've written some code and everything seems to be looking fine but I have trouble inserting text to the Text widget.It doesn't insert all lines just a few.Anyone seems to know the answer?I'm starting with Tkinter and I might move to PyQT.I want to use Python 2.7,so please don't post Python 3.x asnwers.Thanks</p>

<pre><code>import Tkinter as TK
from tkFileDialog import *

#Callbacks
def clearCallback(event):
    print "Clearing..."
    textBox.delete("1.0",TK.END)
    print "Cleared."
return
def openCallback(event):
    print "Trying to open a file..."
    fname = askopenfile(mode='r',initialdir="C:\\")
    if(fname):
        print str(fname)
        content = fname.readlines()
        print str(content)
        for line in content:
            textBox.insert(TK.END,line)
        fname.close()
        return
    else:
        print "No file was opened."
    return
print "---MiniPyE---"
#Base
base = TK.Tk()
base.resizable(height=False,width=False)
base.minsize(650,600)
base.title("MiniPyE")
#Buttons
#Clear Button
clearButton = TK.Button(base,text="New")
clearButton.place(x=16,y=0,height=16,width=48)
clearButton.bind("&lt;Button-1&gt;",clearCallback)
#Open Button
openButton = TK.Button(base,text="Open")
openButton.place(x=16+48,y=0,height=16,width=48)
openButton.bind("&lt;Button-1&gt;",openCallback)
#Text Box
textBox = TK.Text()
textBox.place(x=16,y=16,height = 684,width=650)
#Scrollbar
scrollBar = TK.Scrollbar(base,command=textBox.yview)
scrollBar.place(x=0,y=0,height=584)
#scrollBar.grid(row=0,column=1,sticky='nsew')
base.mainloop()
</code></pre>

<p>I fixed it.The thing was that the height was too big.I changed:<br>
<code>textBox.place(x=16,y=16,height=684,width=650)</code><br>
to<br>
<code>textBox.place(x=16,y=16,height=580)</code><br>
and everything went fine.Just as expected.</p>

python python-2.7 tkinter textbox