I've been working on this little Tkinter address book system. The system is such that, it has a combobox and an entry. I am pulling data from the database to the entry.
Here's the catch, I want the entry to give me the telephone number of the name I selected from the combobox. I picked someones function from here, changed a few things and it still gives me a different output.
Here is the output it gives in the entry:
<sqlite3.Cursor object at 0x102e09f10>
And here is the code.
class MyListbox:
def __init__(self, parent, title):
self.parent = parent
self.parent.title(title)
self.parent.protocol("WM_DELETE_WINDOW", self.closes)
data = cursor.execute('SELECT name FROM addressbook')
self.myData = data
self.establishment()
def combobox_handler(self, event):
current = self.combobox.current()
self.entNumber.delete(0, END)
self.entNumber.insert(END, self.myData)
def establishment(self):
mainFrame = Frame(self.parent)
mainFrame.pack(fill=BOTH, expand=YES)
self.statusBar = Label(mainFrame, text="App",relief=SUNKEN, bd=1)
self.statusBar.pack(side=BOTTOM, fill=X)
fr_left = Frame(mainFrame, bd=10)
fr_left.pack(fill=BOTH, expand=YES, side=LEFT)
names = [person[0] for person in self.myData]
self.combobox = ttk.Combobox(fr_left, values=names)
self.combobox.bind('<<ComboboxSelected>>', self.combobox_handler)
self.combobox.pack()
fr_right = Frame(mainFrame, bd=10)
fr_right.pack(fill=BOTH, expand=YES, side=RIGHT)
fr_up = Frame(fr_right)
fr_up.pack(side=TOP, expand=YES)
Label(fr_up, text='Telephone').grid(row=0, column=0, sticky=W)
self.entNumber = Entry(fr_up)
self.entNumber.grid(row=0, column=1)
def closes(self, event=None):
self.parent.destroy()
Thanks in advance.
See this part in your code current
variable to get the item selected in the combobox
, you should rather insert
that in the entry
widget not myData
from sqlite3
.
def combobox_handler(self, event):
current = self.combobox.current()
self.entNumber.delete(0, END)
self.entNumber.insert(END, self.current)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.