¿Cómo insertar información contenida en una tabla de mysql en un treeview de Tkinter?
Publicado por Didier Omar (2 intervenciones) el 27/03/2019 04:23:09
Saludos, estoy trabajando con python 2 y he creado una pequeña interfaz en la que muestro algunas columnas de un treeview, las cuales me gustaría que estuvieran llenas con información obtenida de una tabla que he creado en mysql pero no comprendo muy bien el codigo que necesito para insertar dicha información tengo un código de ejemplo pero me marca un error en la sintaxis, me gustaría mucho que alguien me pudiera ayudar con dicho código.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def busqueda(self):
root=Tk.Tk()
root.geometry("610x240")
tree=ttk.Treeview(root)
tree["columns"] = ("one", "two", "three", "for")
tree.column("one", width=100)
tree.column("two", width=100)
tree.column("three", width=100)
tree.column("for", width=100)
tree.heading("#0", text='Cedula')
tree.heading("one", text="Nombre(s)")
tree.heading("two", text="Apellido(s)")
tree.heading("three", text="Cargo")
tree.heading("for", text="Telefono")
try:
conexion1=mysql.connector.connect(host="127.0.0.1", user="root", passwd="", database="proyecto")
cursor1=conexion1.cursor()
cursor1.execute("""SELECT Cedula FROM biomedico WHERE cedula =%s""", (i,))
Cedula=cursor1.fetchone()
cursor1.execute("""SELECT Nombres FROM biomedico WHERE cedula =%s""", (i,))
Nombres=cursor1.fetchone()
cursor1.execute("""SELECT Apellidos FROM biomedico WHERE cedula =%s""",(i,))
Apellidos=cursor1.fetchone()
cursor1.execute("""SELECT Cargo FROM biomedico WHERE cedula =%s""",(i,))
Cargo=cursor1.fetchone()
cursor1.execute("""SELECT Telefono FROM biomedico WHERE cedula =%s""",(i,))
Telefono=cursor1.fetchone()
tree.insert("", i, text=i, values=(Cedula, Nombres, Apellidos, Cargo, Telefono)),
tree.pack()
root.mainloop()
Valora esta pregunta


0