繁体   English   中英

Tkinter组合框输入中的输出数据

[英]Tkinter combobox output data in entry

我一直在研究这个小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()

提前致谢。

请参阅代码current变量中的此部分以在combobox选择项目,而应将其insert entry小部件中,而不是sqlite3 myData

   def combobox_handler(self, event):
       current = self.combobox.current()
       self.entNumber.delete(0, END)
       self.entNumber.insert(END, self.current)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM