<br><br><div class="gmail_quote">On Fri, Apr 2, 2010 at 2:25 AM, adedoyin adegoke <span dir="ltr">&lt;<a href="mailto:doyennehoney@yahoo.com">doyennehoney@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>from Tkinter import *</div><div>import MySQLdb</div><div><br></div><div>class Snoop(Frame):</div><div>    def __init__(self, master):</div><div>        Frame.__init__(self, master)</div><div>        self.grid()</div>
<div>
        self.create_widgets()</div><div><br></div><div>    def create_widgets(self):</div><div>        Label(self, text = &quot;Database Name:&quot;).grid(row = 0, column = 0, sticky = W)</div><div>        self.txt_box = Entry(self, text = &quot;hool&quot;).grid(row = 0, column = 1, sticky = W)</div>

<div>        Button(self, text = &quot;Submit&quot;, command = self.connect_db).grid(row = 1, column = 1, sticky = W)</div><div>        Label(self, text = &quot;Tables:&quot;).grid(row = 2, column = 0, sticky = W)</div><div>

       </div><div>        Label(self, text = &quot;Information:&quot;).grid(row = 2, column = 1, sticky = W)</div><div>       # self.txt = Text(self, width = 40, height = 5, wrap = WORD).grid(row = 3, column = 1, sticky = W)</div>

<div>       </div><div>    def connect_db(self):</div><div>        db= MySQLdb.connect(host=&quot;localhost&quot;, user=&quot;root&quot; , passwd=&quot;&quot;)</div><div>        cursor = db.cursor()</div><div>        cursor.execute(&quot;show databases&quot;)</div>

<div><br></div><div>        self.favorite = StringVar()</div><div><br></div><div>        result = cursor.fetchall()</div><div>        i = 4</div><div>        for record in result:</div><div>            Radiobutton(self,</div>

<div>                     text = record,</div><div>                     variable = self.favorite,</div><div>                     value = record,</div><div>                     command = self.update_text</div><div>                     ).grid(row = i, column = 0, sticky = W)</div>

<div>            i+=1</div><div>        </div><div>        #print database</div><div>        #self.txt.delete(0.0, END)</div><div>        #self.get_db(database)</div><div>    def update_text(self):</div><div>        print self.favorite.get()</div>

<div>        trt = self.favorite.get()</div><div>        self.txt_box.insert(END,trt)</div><div><br></div><div>   </div><div><br></div><div>#db.close</div><div>root = Tk()</div><div>root.title(&quot;Snoop&quot;)</div><div>

start = Snoop(root)</div><div><br></div><div>root.mainloop()</div><div><br></div><div><br></div><div><br></div><div>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 ;</div>

<div><br></div><div>Exception in Tkinter callback</div><div>Traceback (most recent call last):</div><div>  File &quot;/usr/lib/python2.6/lib-tk/Tkinter.py&quot;, line 1413, in __call__</div><div>    return self.func(*args)</div>

<div>  File &quot;/home/NetBeansProjects/python/src/Xsnoop.py&quot;, line 45, in update_text</div><div>    self.txt_box.insert(END,trt)</div><div>AttributeError: &#39;NoneType&#39; object has no attribute &#39;insert&#39;</div>

<div>   </div><div><br></div><div>How can i correct this?</div><div><br></div>
<br>_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><div><br></div>Is this line printing anything:<div><br></div><div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
&quot;print self.favorite.get()&quot;?</blockquote><div><br></div><div><br></div><div>I would try something like this:</div><div><br></div><div>Move this to the &quot;__init__&quot;:</div><div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
self.favorite = StringVar()</blockquote><div><br></div><div>Change this:</div><div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
self.txt_box = Entry(self, text = &quot;hool&quot;).grid(row = 0, column = 1, sticky = W)</blockquote><div><br></div><div>to this:</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
self.txt_box = Entry(self, text = <a href="http://self.name">self.name</a>).grid(row = 0, column = 1, sticky = W)</blockquote><div><br></div><div>in the &quot;__init__&quot; add two lines:</div><div><br></div><div> </div>
<div><a href="http://self.name">self.name</a> = StringVar()</div><div>self.name.set(&quot;hool&quot;)</div><div><br></div><div>In update_text change this:</div><div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
self.txt_box.insert(END,trt)</blockquote><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">to this:</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
self.name.set(trt)</blockquote><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><br></div><div><br></div><div><br></div><div><br>
</div><div><br></div></div>