<br><br><div class="gmail_quote">On Fri, Apr 2, 2010 at 2:25 AM, adedoyin adegoke <span dir="ltr"><<a href="mailto:doyennehoney@yahoo.com">doyennehoney@yahoo.com</a>></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 = "Database Name:").grid(row = 0, column = 0, sticky = W)</div><div> self.txt_box = Entry(self, text = "hool").grid(row = 0, column = 1, sticky = W)</div>
<div> Button(self, text = "Submit", command = self.connect_db).grid(row = 1, column = 1, sticky = W)</div><div> Label(self, text = "Tables:").grid(row = 2, column = 0, sticky = W)</div><div>
</div><div> Label(self, text = "Information:").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="localhost", user="root" , passwd="")</div><div> cursor = db.cursor()</div><div> cursor.execute("show databases")</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("Snoop")</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 "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__</div><div> return self.func(*args)</div>
<div> File "/home/NetBeansProjects/python/src/Xsnoop.py", line 45, in update_text</div><div> self.txt_box.insert(END,trt)</div><div>AttributeError: 'NoneType' object has no attribute 'insert'</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; ">
"print self.favorite.get()"?</blockquote><div><br></div><div><br></div><div>I would try something like this:</div><div><br></div><div>Move this to the "__init__":</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 = "hool").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 "__init__" add two lines:</div><div><br></div><div> </div>
<div><a href="http://self.name">self.name</a> = StringVar()</div><div>self.name.set("hool")</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>