Python - Ayuda a un recien iniciado con la creación de una agenda

 
Vista:
Imágen de perfil de juan antonio

Ayuda a un recien iniciado con la creación de una agenda

Publicado por juan antonio (1 intervención) el 18/06/2016 19:47:48
Hola amigos, les cuento que recien empeze la carrera de ing. en computacion e informatica :D recien vamos por temas como while, random, cosas basicas pero le agarre el gustillo, ahora trato de hacer una agenda con tkinter usando funciones y creando archivos, he llegado hasta la parte de la creacion de la agenda y logro guardar en el archivo nuevo, pero cuando cierro y vuelvo a abrir el programa, este aparece sin datos y veo que se crea un archiv o nuevo borrando el atenrior donde guardaba los codigos, alguien puede hecharle un vistazo para ver que estoy haciendo mal? :/

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# _*_ coding:utf-8 _*_
from Tkinter import *
lista = []
def guardar():
    nombre = nombres.get()
    direccio = direccion.get()
    ciuda = ciudad.get()
    telefoo = telefono.get()
    emai = email.get()
    lista.append(nombre+";"+direccio+";"+ciuda+";"+telefoo+";"+emai)
    escribir_contacto()
    nombres.set("")
    direccion.set("")
    ciudad.set("")
    telefono.set("")
    email.set("")
    consultar()
def eliminar():
     print "sin terminar"
def consultar():
    r = Text(agenda,width=80)
    lista.sort()
    valores = []
    r.insert(INSERT,"Nombres:\t\tDirección:\t\tCiudad:\t\tTeléfono:\t\tEmail:\n")
    for elemento in lista:
        arreglo = elemento.split(";")
        valores.append(arreglo[0])
        r.insert(INSERT, arreglo[0]+"\t\t"+arreglo[1]+"\t\t"+arreglo[2]+"\t\t"+arreglo[3]+"\t\t"+arreglo[4]+"\n")
    r.place(x=20,y=210)
    spinnombre = Spinbox(agenda,value=(valores),textvariable=contactoeliminar,width=30).place(x=450,y=90)
    if lista == []:
        spinnombre = Spinbox(agenda,value=(valores)).place(x=450,y=90)
    r.config(state=DISABLED)
def iniciar_archivo():
    archivo = open("contactos.txt","a")
    archivo.close()
def cargar():
    archivo = open("contactos.txt","r")
    linea = archivo.readline()
    if linea:
        while linea:
            if linea[-1] == "\n":
                linea = linea[:1]
            lista.append(linea)
            linea = archivo.readline()
    archivo.close()
def escribir_contacto():
    archivo = open("contactos.txt","w")
    lista.sort()
    for elemento in lista:
        archivo.write(elemento+"\n")
    archivo.close()
#Iniciamos la agenda                     
agenda = Tk()
nombres = StringVar()
direccion = StringVar()
ciudad = StringVar()
telefono = StringVar()
email = StringVar()
contactoeliminar = StringVar()
agenda.title("Mi Agenda Personal")
agenda.geometry("700x600")
agenda.resizable(0,0)
color_fondo = "#000000"
iniciar_archivo()
consultar()
cargar()
escribir_contacto()
#entradas para contacto
agenda_titulo = Label(agenda,text="Agenda Personal",font=("Helvetica",12),anchor="center").pack()
agenda_descripcion = Label(agenda,text="Una agenda personal diseñada por Juan Antonio Soto Cabrera para el curso de Técnicas de programación",anchor="center").pack()
nombre_titulo = Label(agenda,text="Ingresar nombre de contacto:").place(x=30,y=60)
caja_nombre = Entry(agenda,textvariable=nombres,width=30).place(x=200,y=60)
direccion_titulo = Label(agenda,text="Ingresa dirreción del contacto:").place(x=30,y=90)
caja_nombre = Entry(agenda,textvariable=direccion,width=30).place(x=200,y=90)
direccion_titulo = Label(agenda,text="Ingresa ciudad del contacto:").place(x=30,y=120)
caja_nombre = Entry(agenda,textvariable=ciudad,width=30).place(x=200,y=120)
telefono_titulo = Label(agenda,text="Ingresa teléfono del contacto:").place(x=30,y=150)
caja_nombre = Entry(agenda,textvariable=telefono,width=30).place(x=200,y=150)
email_titulo = Label(agenda,text="Ingresa email del contacto:").place(x=30,y=180)
caja_nombre = Entry(agenda,textvariable=email,width=30).place(x=200,y=180)
#opciones de guardar y borrar
eliminar_titulo = Label(agenda,text="Eliminar contacto:").place(x=450,y=60)
spinnombre = Spinbox(agenda,textvariable=contactoeliminar,width=30).place(x=450,y=90)
boton_eliminar = Button(agenda,text="Eliminar contácto",command=eliminar).place(x=450,y=120)
boton_guardar = Button(agenda,text="Guardar contácto",command=guardar).place(x=450,y=180)
mainloop()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Ayuda a un recien iniciado con la creación de una agenda

Publicado por Horacio (19 intervenciones) el 02/07/2016 21:12:45
fijate si te sirve le hice algunos cambios:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# _*_ coding:utf-8 _*_
from Tkinter import *
 
lista = []
 
def guardar():
 
    nombre = nombres.get()
 
    direccio = direccion.get()
 
    ciuda = ciudad.get()
 
    telefoo = telefono.get()
 
    emai = email.get()
 
    contacto = nombre+";"+direccio+";"+ciuda+";"+telefoo+";"+emai
 
    lista.append(contacto)
 
    escribir_contacto(contacto)
 
    nombres.set("")
 
    direccion.set("")
 
    ciudad.set("")
 
    telefono.set("")
 
    email.set("")
 
    consultar()
 
def eliminar():
 
     print "sin terminar"
 
def consultar():
 
    r = Text(agenda,width=80)
 
    lista.sort()
 
    valores = []
 
    r.insert(INSERT,"Nombres:\t\tDirección:\t\tCiudad:\t\tTeléfono:\t\tEmail:\n")
 
    for elemento in lista:
 
        arreglo = elemento.split(";")
 
        valores.append(arreglo[0])
 
        r.insert(INSERT, arreglo[0]+"\t\t"+arreglo[1]+"\t\t"+arreglo[2]+"\t\t"+arreglo[3]+"\t\t"+arreglo[4]+"\n")
 
    r.place(x=20,y=210)
 
    spinnombre = Spinbox(agenda,value=(valores),textvariable=contactoeliminar,width=30).place(x=450,y=90)
 
    if lista == []:
 
        spinnombre = Spinbox(agenda,value=(valores)).place(x=450,y=90)
 
    r.config(state=DISABLED)
 
def iniciar_archivo():
 
    archivo = open("contactos.txt","w")
 
    archivo.close()
 
def cargar():
 
    try:
        archivo = open("contactos.txt","r")
    except IOError:
        iniciar_archivo()
        return
 
    linea = archivo.readline()
 
 
    while linea != '':
 
        linea.strip()
 
        lista.append(linea)
 
        linea = archivo.readline()
 
    archivo.close()
 
def escribir_contacto(contacto):
 
    archivo = open("contactos.txt","a")
 
    archivo.write(contacto + "\n")
 
    archivo.close()
 
#Iniciamos la agenda
 
agenda = Tk()
 
nombres = StringVar()
 
direccion = StringVar()
 
ciudad = StringVar()
 
telefono = StringVar()
 
email = StringVar()
 
contactoeliminar = StringVar()
 
agenda.title("Mi Agenda Personal")
 
agenda.geometry("700x600")
 
agenda.resizable(0,0)
 
color_fondo = "#000000"
 
cargar()
 
consultar()
 
 
#entradas para contacto
 
agenda_titulo = Label(agenda,text="Agenda Personal",font=("Helvetica",12),anchor="center").pack()
 
agenda_descripcion = Label(agenda,text="Una agenda personal diseñada por Juan Antonio Soto Cabrera para el curso de Técnicas de programación",anchor="center").pack()
 
nombre_titulo = Label(agenda,text="Ingresar nombre de contacto:").place(x=30,y=60)
 
caja_nombre = Entry(agenda,textvariable=nombres,width=30).place(x=200,y=60)
 
direccion_titulo = Label(agenda,text="Ingresa dirreción del contacto:").place(x=30,y=90)
 
caja_nombre = Entry(agenda,textvariable=direccion,width=30).place(x=200,y=90)
 
direccion_titulo = Label(agenda,text="Ingresa ciudad del contacto:").place(x=30,y=120)
 
caja_nombre = Entry(agenda,textvariable=ciudad,width=30).place(x=200,y=120)
 
telefono_titulo = Label(agenda,text="Ingresa teléfono del contacto:").place(x=30,y=150)
 
caja_nombre = Entry(agenda,textvariable=telefono,width=30).place(x=200,y=150)
 
email_titulo = Label(agenda,text="Ingresa email del contacto:").place(x=30,y=180)
 
caja_nombre = Entry(agenda,textvariable=email,width=30).place(x=200,y=180)
 
#opciones de guardar y borrar
 
eliminar_titulo = Label(agenda,text="Eliminar contacto:").place(x=450,y=60)
 
spinnombre = Spinbox(agenda,textvariable=contactoeliminar,width=30).place(x=450,y=90)
 
boton_eliminar = Button(agenda,text="Eliminar contácto",command=eliminar).place(x=450,y=120)
 
boton_guardar = Button(agenda,text="Guardar contácto",command=guardar).place(x=450,y=180)
 
mainloop()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar