UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2: ordinal not in range(128)
My all Python code is :
#! /usr/bin/python
#-*- coding:Utf-8-*-
from Tkinter import *
import ttk
import psycopg2
def center(window):
sw = window.winfo_screenwidth()
sh = window.winfo_screenheight()
rw = window.winfo_reqwidth()
rh = window.winfo_reqheight()
xc = (sw - rw) / 2
yc = (sh -rh) / 2
window.geometry("+%d+%d" % (xc, yc))
window.deiconify()
def afficher() :
connect()
cur = conn.cursor()
cur.execute("""SELECT * from firstbasetable""")
rows = cur.fetchall()
if rows :
for z in rows:
print z[1] + ' : ' + str(z[2])
tv.insert("","end", values=(z[1], z[2], z[3]))
def connect() :
global conn
conn = psycopg2.connect("host='localhost' dbname='firstbase' user='postgres' password='pesbakpostgresql'")
fenetre=Tk()
fenetre.geometry("500x400")
fenetre.title(' Test Data')
firstnamevar = StringVar()
lastnamevar = StringVar()
Phonevar = IntVar()
f1 = Frame(fenetre, bg="#290080", width=500, height=500)
f1.pack( fill=X, expand=0)
lab1 = Label(fenetre, text="Voila la table testtable de la base testbase" , bg = "#290080", fg = "white" )
lab1.place ( x=100 , y=15 )
lab1 = Label(fenetre, text="Prénom" , bg = "#290080", fg = "white" )
lab1.place ( x=30 , y=100 )
lab1 = Label(fenetre, text="Nom" , bg = "#290080", fg = "white" )
lab1.place ( x=30 , y=125)
lab1 = Label(fenetre, text="Phone" , bg = "#290080", fg = "white" )
lab1.place ( x=30 , y=150)
firstname_entry = ttk.Entry(fenetre, width=15, textvariable=firstnamevar)
firstname_entry.place (x = 100 , y = 100 )
lastname_entry = ttk.Entry(fenetre, width=15, textvariable=lastnamevar)
lastname_entry.place (x = 100 , y = 125 )
Phone_entry = ttk.Entry(fenetre, width=15, textvariable=Phonevar)
Phone_entry.place (x = 100 , y = 150 )
Phonevar.set("")
scrollbar = Scrollbar(fenetre)
scrollbar.place (x = 412 , y = 301 )
tv = ttk.Treeview(fenetre, show='headings', height =3, yscrollcommand=scrollbar.set)
tv["columns"]=("col1","col2","col3")
tv.column("col1",width=100,anchor="center", stretch = True, minwidth = 50)
tv.column("col2",width=100,anchor="center")
tv.column("col3",width=110,anchor="center")
tv.heading("col1",text="Prénom")
tv.heading("col2",text="Nom")
tv.heading("col3",text="Phone number")
tv.place( x = 100 , y = 250 )
scrollbar.config(command=tv.yview)
afficher = Button(fenetre, text = "Afficher" , command = afficher)
afficher.place( x=315, y=80 )
inserer = Button(fenetre, text = "Inserer" , command = insere)
inserer.place( x=315, y=110 )
modifier = Button(fenetre, text = "Modifier" ) #, command = modif)
modifier.place( x=315, y=140 )
supprimer = Button(fenetre, text = "Supprimer" , command = afficheselected)
supprimer.place( x=315, y=170 )
Quitter = Button(fenetre, text = "Quitter" , command = fenetre.quit)
Quitter.place( x=200, y=350 )
fenetre.after(0,center,fenetre)
fenetre.mainloop()
The line where the execution is blocked is :
tv.insert("",0, values=(z[1], z[2], z[3]))
In my datas there is "Prénom1" and "Prénom2"
On the terminale the code works very good and print my datas with "é"
Thank you very much for helping me friends

New Topic/Question
Reply



MultiQuote




|