[ Foro de Python ]
Quiero mostrar unos valores de una base de datos pais (Id, Nombre) me dibuja la tabla y todo perfecto PERO A LA HORA DE HACER EL INCERT, simplemente no hace nada ni muestra error, que estoy haciendo mal?
he aqui el codigo:
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import psycopg2
class Pais:
def __init__(self,raiz):
self.raiz=raiz
self.raiz.title("NOMBRE")
self.raiz.geometry("1400x800+0+0")
self.raiz.config(bd=20)
self.raiz.config(relief="groove")
marco =LabelFrame(self.raiz, text="MODULO PAIS", font="Arial 14
bold",foreground="red",labelanchor='n',height=500,width=800,borderwidth=15,highlightcolor='blue')
marco.pack()
nombrePais = StringVar()
l2 = Label(marco, font="arial 12", text="Nombre País :")
l2.place(x=50, y=10)
e2 = Entry(marco, textvariable=nombrePais, width=90)
e2.place(x=170, y=10)
#AREA DE BOTONES
bt1 = Button(marco, text="Incluir País", bg='spring green', font="Arial 12", command=0)
bt1.place(x=50, y=90)
bt2 = Button(marco, text="Modificar País", bg='gold2', font="Arial 12", command=0)
bt2.place(x=170, y=90)
bt3 = Button(marco, text="Borrar País", bg='OrangeRed2', font="Arial 12", command=0)
bt3.place(x=305, y=90)
bt4 = Button(marco, text="Listar Paises", bg='DeepSkyBlue2', font="Arial 12", command=0)
bt4.place(x=425, y=90)
bt5 = Button(marco, text="Salir Modulo País", bg='red', font="Arial 12", command=0)
bt5.place(x=550, y=90)
############# TABLA ###########
self.tabla = ttk.Treeview(self.raiz, height=12, columns=2)
self.tabla.place(x=360, y=180)
self.tabla.column("#0", width="100")
self.tabla.heading("#0", text="CODIGO - ID", anchor=CENTER)
self.tabla.column("#1", width="500")
self.tabla.heading("#1", text="NOMBRE PAIS", anchor=CENTER)
scrollbar_horizontal = ttk.Scrollbar(self.raiz, orient='horizontal', command=self.tabla.xview)
scrollbar_vertical = ttk.Scrollbar(self.raiz, orient='vertical', command=self.tabla.yview)
self.tabla.configure(xscrollcommand=scrollbar_horizontal.set, yscrollcommand=scrollbar_vertical.set)
############# FIN DE TABLA ###########
def mostrar_pais(self):
try:
miConexion = psycopg2.connect(host="localhost", database="bdherplac", user="postgres", port="5432",
password="12345")
except psycopg2.erros as e:
messagebox.showwarning("ADVERTENCIA", "A ocurrido un error ", "Verifique conexxion a BD")
miCursor = miConexion.cursor()
registros=self.tabla.get_children()
for (elemento) in registros:
self.tabla.delete(elemento)
try:
miCursor = self.consulta_pais("SELECT * FROM pais ")
for row in miCursor:
#print(row[0])
#print(row[1])
self.tabla.insert(' ', 0, text=row[0], values=row[1])
except:
pass
if __name__=="__main__":
raiz=Tk()
app=Pais(raiz)
app.mostrar_pais()
raiz.mainloop()
(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)