[Tkinter-discuss] Learning Python/Tkinter and struggling with the text object

Alan L Dickman adickman at us.ibm.com
Thu Dec 8 13:00:50 EST 2016


Thanks in advance for any help! I'm just learning Python and Tkinter. Can 
anyone suggest why this program does not insert 'some text' into text box 
t1 when the start button is clicked? No errors are thrown when I run the 
program in PyCharm

from tkinter import *

class Window(Frame):
    t1 = []
    def __init__(self, master=None)
        Frame.__init__(self, master)
        self.master = master
        self.master.title("My Title")
        StartButton = Button(self, text="Start", command=self.start, bg=
'#006ba6', fg="white")
        StartButton.grid(row=0, columnspan=3, sticky=(N, S, W, E))
        Label(self, text="Your Name").grid(row=1, sticky=(N, S, W, E))
        t1 = Text(self, height=2)
        t1.grid(row=1, column=1, sticky=(N, S, W, E))
        self.t1.insert( 0, 'some text')
        quitButton = Button(self, text="Quit", command=self.client_quit, 
bg='#006ba6', fg="white")
        quitButton.grid(row=5, columnspan=3, sticky=(N, S, W, E))
        self.grid(sticky=(N, S, W, E))

    def start(self):
        self.t1.insert(0, 'some text')

    def client_quit(self):
        exit()

root = Tk()
root.geometry()
app = Window(root)
root.mainloop()

Alan Dickman
IBM Cloud Technical Sales Specialist, Process Transformation
North America Public Sector
Email: adickman at us.ibm.com 
Mobile: +1 303 324 9353 
Find me on: LinkedIn 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20161208/586de135/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 19179 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20161208/586de135/attachment-0001.png>


More information about the Tkinter-discuss mailing list