我一直在研究这个小小的Tkinter通讯录系统。 该系统具有组合框和入口。我将数据从数据库中提取到条目中。
这是一个问题,我希望该条目能够为我提供从组合框中选择的名称的电话号码。我从这里选择了某些功能,改变了一些东西,它仍然给了我不同的输出。
以下是条目中的输出:
<sqlite3.Cursor object at 0x102e09f10>
这是代码。
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()
提前致谢。
答案 0 :(得分:0)
在代码current
变量中查看此部分以获取combobox
中选中的项目,您应该insert
entry
小部件中的myData
sqlite3
来自 def combobox_handler(self, event):
current = self.combobox.current()
self.entNumber.delete(0, END)
self.entNumber.insert(END, self.current)
。
<tr>