Thanks guys I was able to resolve it by changing self.txt_box = Entry(self, text = "hool").grid(row = 0, column = 1, sticky = W)
to self.txt_box = Entry(self, text = "hool") self.txt_box.grid(row = 0, column = 1, sticky = W) and self.txt_box.insert(END,trt) to self.txt_box.insert(0,trt) but i added self.txt_box.delete(0, END) before inserting ________________________________ From: James Reynolds <eire1...@gmail.com> To: adedoyin adegoke <doyenneho...@yahoo.com> Sent: Sun, April 4, 2010 9:35:37 PM Subject: Re: [Tutor] Display in a text field using tkinter Did you try setting this (in the init): self.create_widgets() to something like this: my_object = self.create_widgets() ? On Fri, Apr 2, 2010 at 2:25 AM, adedoyin adegoke <doyenneho...@yahoo.com> wrote: from Tkinter import * >import MySQLdb > > >class Snoop(Frame): > def __init__(self, master): > Frame.__init__(self, master) > self.grid() >> self.create_widgets() > > > def create_widgets(self): > Label(self, text = "Database Name:").grid(row = 0, column = 0, sticky > = W) > self.txt_box = Entry(self, text = "hool").grid(row = 0, column = 1, > sticky = W) > Button(self, text = "Submit", command = self.connect_db).grid(row = 1, > column = 1, sticky = W) > Label(self, text = "Tables:").grid(row = 2, column = 0, sticky = W) >> > > Label(self, text = "Information:").grid(row = 2, column = 1, sticky = > W) > # self.txt = Text(self, width = 40, height = 5, wrap = WORD).grid(row = > 3, column = 1, sticky = W) > > def connect_db(self): > db= MySQLdb.connect(host="localhost", user="root" , passwd="") > cursor = db.cursor() > cursor.execute("show databases") > > > self.favorite = StringVar() > > > result = cursor.fetchall() > i = 4 > for record in result: > Radiobutton(self, > text = record, > variable = self.favorite, > value = record, > command = self.update_text > ).grid(row = i, column = 0, sticky = W) > i+=1 > > #print database > #self.txt.delete(0.0, END) > #self.get_db(database) > def update_text(self): > print self.favorite.get() > trt = self.favorite.get() > self.txt_box.insert(END,trt) > > > > > >#db.close >root = Tk() >root.title("Snoop") >> >start = Snoop(root) > > >root.mainloop() > > > > > > >The above code will snoop and fetch all d available databases using tkinter. >When I select one of these databases, the name should be inserted in a text >field instead it throws the following error ; > > >Exception in Tkinter callback >Traceback (most recent call last): > File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__ > return self.func(*args) > File "/home/NetBeansProjects/python/src/Xsnoop.py", line 45, in update_text > self.txt_box.insert(END,trt) >AttributeError: 'NoneType' object has no attribute 'insert' > > > >How can i correct this? > > >_______________________________________________ >>Tutor maillist - Tutor@python.org >>To unsubscribe or change subscription options: >http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor