-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProyecto_2.py
4027 lines (3940 loc) · 238 KB
/
Proyecto_2.py
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
def programa():
"Proyecto programado#2: Kevin Salazar"
import tkinter as tk
from tkinter import messagebox as mb
from tkinter import ttk
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
Acepción de la contraseña
Entrada: el usuario y la contraseña
Salida: acceso a la parte administrativa
"""
def paseAdmin():
contraseña= tk.Tk()
contraseña.title("Confirmar usuario")
ancho_contraseña= 400
alto_contraseña= 500
#Porción de código para centrar la ventana a la pantalla
x_ventana=contraseña.winfo_screenwidth() // 2 - ancho_contraseña // 2
y_ventana=contraseña.winfo_screenheight() // 2 - alto_contraseña // 2
posicion=str(ancho_contraseña)+"x"+str(alto_contraseña)+"+"+str(x_ventana)+"+"+str(y_ventana)
contraseña.geometry(posicion)
contraseña.resizable(0,1)
contraseña.iconbitmap("img.ico")
def validar(): #Validación de la contaseña
usuario=user.get()
entrada=contra.get()
f=open("contraseña.txt", "r")
codigo=f.read()
f.close()
if usuario!="Admin":
error=tk.Label(contraseña, text="Este usuario no existe.", font="Helvetica 10", fg="red").place(x=100, y=155)
else:
error=tk.Label(contraseña, text=" ", font="Helvetica 10", fg="red").place(x=100, y=155)
if entrada!=codigo:
error=tk.Label(contraseña, text="La contraseña es inválida.", font="Helvetica 10", fg="red").place(x=100, y=240)
else:
error=tk.Label(contraseña, text=" ", font="Helvetica 10", fg="red").place(x=100, y=240)
permiso=mb.showinfo(title="Info", message="Acceso concedido")
contraseña.destroy()
return administrador()
label1=tk.Label(contraseña, text="Acceso restringido", font=("Helvetica", 14, "italic")).pack()
label2=tk.Label(contraseña, text="Continuar al Sector administrativo", font=("Helvetica", 12, "italic")).pack()
label3=tk.Label(contraseña, text="Usuario", font=("Helvetica", 14)).place(x=160, y=100)
user=tk.Entry(contraseña, font="Helvetica 12")
user.place(x=100, y=130)
label4=tk.Label(contraseña, text="Digite su contraseña", font=("Helvetica", 14)).place(x=100, y=190)
contra=tk.Entry(contraseña, font="Helvetica 12", show="*")
contra.place(x=100, y=220)
valid=tk.Button(contraseña, text="Validar contraseña", font=("Helvetica",14), bg="gray", width="16",height="1",relief="groove", command=validar, cursor="hand2").place(x=100, y=300)
contraseña.mainloop()
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Funciones del administrador
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
def Empresas(): #Ventana principal de las funciones de empresas
GestionEmpresa= tk.Toplevel()
#Porción de código para centrar la ventana a la pantalla
width= GestionEmpresa.winfo_screenwidth()
height= GestionEmpresa.winfo_screenheight()
GestionEmpresa.geometry("%dx%d" % (width, height))
GestionEmpresa.resizable(0,1)
#====================Funciones Auxiliares de gestión de empresas====================#
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
IncluirEmpresa
Como el nombre lo dice, sirve para agregar una empresa a la base de datos
Entradas:
La cédula jurídica de la empresa
El nombre de la empresa
Su ubicación
Salida:
Los datos obtenidos serán guardados en el archivo 'Empresas.txt'
"""
def IncluirEmpresa():
nuevaEmpresa=tk.Toplevel()
nuevaEmpresa.geometry("450x600")
nuevaEmpresa.title("Incluir Empresa")
nuevaEmpresa.iconbitmap("img.ico")
nuevaEmpresa.resizable(0,1)
Cedula=tk.Label(nuevaEmpresa,text="Cédula Jurídica", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=50)
cedula=tk.IntVar()
datoCedula=tk.Entry(nuevaEmpresa, width=14, relief="sunken", textvariable=cedula)
datoCedula.place(x=200, y=64)
def contarDigitos(num):
if num==0:
return 1
else:
res=0
while num>0:
res+=1
num//=10
return res
def validarNuevaEmpresa(): #Valida que la cédula tenga 10 dígitos
numCedula=datoCedula.get()
if(contarDigitos(int(numCedula))!=10):
error=tk.Label(nuevaEmpresa, text="Error: La cédula debe tener 10 dígitos", font=("Sans Serif", 10), width=30, height=1, fg="red").place(x=200, y=86)
else:
correcto=tk.Label(nuevaEmpresa, text=" ", font=("Sans Serif", 10), width=30, height=1).place(x=200, y=86)
if(SeEncuentra("Empresas.txt", numCedula)):
error=tk.Label(nuevaEmpresa, text="Error: La cédula ya se encuentra registrada", font=("Sans Serif", 10), width=32, height=1, fg="red").place(x=194, y=86)
else:
Empresa=datoNombre.get()
provincia=provincias.get()
ubicacion=direccion.get("1.0", "end-1c")
f=open("Empresas.txt", "a")
f.write(str(numCedula)+"|"+str(Empresa)+"|"+str(provincia)+", "+str(ubicacion)+"\n")
f.close()
hecho=mb.showinfo(title="Información", message="La empresa se agregó exitosamente")
nuevaEmpresa.destroy()
return Empresas()
"""
SeEncuentra
E: un archivo y una palabra para buscarla en el archivo
S: Si la palabra se encuentra en el archivo, retornará True, sino False
"""
def SeEncuentra(archivo, palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista): #f.readlines convierte el texto a lista
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return False
else:
return buscarAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return True
Nombre=tk.Label(nuevaEmpresa, text="Nombre de la empresa", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=120)
datoNombre=tk.Entry(nuevaEmpresa, width=14, relief="sunken")
datoNombre.place(x=200, y=136)
Ubic=tk.Label(nuevaEmpresa, text="-------------Ubicación-------------", font=("Sans Serif", 12), width=35, height= 2).place(x=55, y=170)
Provincia=tk.Label(nuevaEmpresa, text= "Provincia", font=("Sans Serif", 12),width=15, height=2).place(x=15,y=210)
provincias=ttk.Combobox(nuevaEmpresa)
provincias.place(x=155, y=223)
provincias["values"]=("San José", "Alajuela","Cartago","Heredia", "Guanacaste", "Puntarenas", "Limón")
provincias.current(0)
Direccion=tk.Label(nuevaEmpresa, text="Dirección exacta", font=("Sans Serif", 12), width=15, height=2).place(x=150, y=270)
direccion=tk.Text(nuevaEmpresa, width=35, height=6, font=("Sans Serif", 12))
direccion.place(x=61, y=320)
validacion=tk.Button(nuevaEmpresa, text="Validar", font=("Sans Serif", 12), width=15, height=2, bg="grey", command=validarNuevaEmpresa).place(x=150, y=500)
nuevaEmpresa.mainloop()
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
BorrarEmpresas
Dada la cédula de una empresa, elimina la empresa que esté vinculada con dicha cédula
E: la cédula
S: Borra la empresa del archivo 'Empresas.txt'
R: No puede borrarse aquella empresa que esté vinculada a un transporte
"""
def BorrarEmpresas():
borrarempresa= tk.Tk()
borrarempresa.title("Borrar empresa")
ancho_pantalla= 400
alto_pantalla= 120
#Porción de código para centrar la ventana a la pantalla
x_ventana=borrarempresa.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=borrarempresa.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
borrarempresa.geometry(posicion)
borrarempresa.resizable(0,1)
borrarempresa.iconbitmap("img.ico")
"""
buscarPalabra
E: un archivo y una palabra para buscarla en el archivo
S: Si la palabra se encuentra en el archivo, retornará la línea en la cual está ubicada
"""
def buscarPalabra(archivo,palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarPalabraAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista):
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarPalabraAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return "Sin resultados"
else:
return buscarPalabraAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarPalabraAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarPalabraAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarPalabraAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return res
"""
BorrarLinea
Dada una palabra clave, borra una linea de un archivo en la cual se encuentra dicha palabra:
"""
def borrarLinea():
identif=empresa.get()
lineaAborrar=buscarPalabra("Empresas.txt", identif)
if lineaAborrar=="Sin resultados":
info=mb.showerror(title="Error en entrada", message="No se encontraron coincidencias")
borrarempresa.destroy()
return BorrarEmpresas()
if(SeEncuentra("Transportes.txt", identif)):
info=mb.showerror(title="Error en entrada", message="No se puede borrar.\nLa empresa está asociada a un transporte")
borrarempresa.destroy()
return Empresas()
else:
f = open("Empresas.txt","r")
lineas = f.readlines()
f.close()
f = open("Empresas.txt","w")
while lineas!=[]:
if lineas[0]!=lineaAborrar:
f.write(lineas[0])
lineas=lineas[1:]
else:
lineas=lineas[1:]
f.close()
info=mb.showinfo(title="Estado", message="La empresa se eliminó exitosamente")
borrarempresa.destroy()
return Empresas()
def SeEncuentra(archivo, palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista): #f.readlines convierte el texto a lista
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return False
else:
return buscarAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return True
label=tk.Label(borrarempresa, text="Digite la cédula de la empresa a borrar", font=("Sans serif", 14)).pack()
empresa=tk.Entry(borrarempresa, font="Helvetica 12")
empresa.pack()
borrar=tk.Button(borrarempresa, text="Borrar", font=("Helvetica",14), bg="#6ee2ff", width="16",height="1",relief="groove", command=borrarLinea, cursor="hand2").pack()
borrarempresa.mainloop()
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
ModificarEmpresas
Se selecciona una empresa de la lista de empresas, para posteriormente modificar sus campos
Entrada:
la empresa seleccionada (se buscará por cédula y se editará los campos de Nombre y ubicación)
Salida:
Los cambios se registrarán en el archivo 'Empresas.txt'
"""
def modificarEmpresas():
f=open("Empresas.txt", "r")
info=f.readlines()
f.close()
if info==[]:
mensaje=mb.showinfo(title="Atención", message="No hay empresas registradas")
return Empresas()
else:
modifEmpresa=tk.Toplevel()
ancho_pantalla= 400
alto_pantalla= 400
#Porción de código para centrar la ventana a la pantalla
x_ventana=modifEmpresa.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=modifEmpresa.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
modifEmpresa.geometry(posicion)
modifEmpresa.title("Ver Empresas")
modifEmpresa.iconbitmap("img.ico")
modifEmpresa.config(bg="grey")
modifEmpresa.resizable(0,1)
def modifCamposEmpresa():
num=int(emp.get())
Datos=ListaEmpresas.get(num)
Cedulaempresa=Datos[3:13]
RestoDeDatos=recopilarDatos(Datos[14:-4])
NombreAntiguo=RestoDeDatos[0]
UbicAntigua=RestoDeDatos[1]
modifEmpresa.destroy()
return modifCamposEmpresaAux(Cedulaempresa, NombreAntiguo, UbicAntigua)
def modifCamposEmpresaAux(Cedulaempresa, NombreAntiguo, UbicAntigua):
modifEmpresa2=tk.Toplevel()
#Porción de código para centrar la ventana a la pantalla
ancho_pantalla= 450
alto_pantalla= 600
x_ventana=modifEmpresa2.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=modifEmpresa2.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
modifEmpresa2.geometry(posicion)
modifEmpresa2.title("Modificar Empresa")
modifEmpresa2.iconbitmap("img.ico")
modifEmpresa2.resizable(0,1)
Cedula=tk.Label(modifEmpresa2,text="Cédula Jurídica", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=50)
datoCedula=tk.Entry(modifEmpresa2, width=14, relief="sunken")
datoCedula.place(x=200, y=64)
datoCedula.insert(0, Cedulaempresa)
datoCedula.config(state=tk.DISABLED)
def AgregarEmpresaModificada(): #Función para agregar la empresa modificada
Cedula=datoCedula.get()
Empresa=datoNombre.get()
provincia=provincias.get()
ubicacion=direccion.get("1.0", "end-1c")
lineaAmodificar=buscarPalabra("Empresas.txt", Cedula)
f = open("Empresas.txt","r")
lineas = f.readlines()
f.close()
f = open("Empresas.txt","w")
while lineas!=[]:
if lineas[0]!=lineaAmodificar:
f.write(lineas[0])
lineas=lineas[1:]
else:
f.write(str(Cedula)+"|"+str(Empresa)+"|"+str(provincia)+", "+str(ubicacion))
lineas=lineas[1:]
f.close()
info=mb.showinfo(title="Estado", message="La empresa se modificó exitosamente")
modifEmpresa2.destroy()
return Empresas()
def buscarPalabra(archivo,palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarPalabraAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista):
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarPalabraAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return "Sin resultados"
else:
return buscarPalabraAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarPalabraAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarPalabraAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarPalabraAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return res
Nombre=tk.Label(modifEmpresa2, text="Nombre de la empresa", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=120)
datoNombre=tk.Entry(modifEmpresa2, width=14, relief="sunken")
datoNombre.place(x=200, y=136)
datoNombre.insert(0, NombreAntiguo)
Ubic=tk.Label(modifEmpresa2, text="-------------Ubicación-------------", font=("Sans Serif", 12), width=35, height= 2).place(x=55, y=170)
Provincia=tk.Label(modifEmpresa2, text= "Provincia", font=("Sans Serif", 12),width=15, height=2).place(x=15,y=210)
provincias=ttk.Combobox(modifEmpresa2)
provincias.place(x=155, y=223)
provincias["values"]=("San José", "Alajuela","Cartago","Heredia", "Guanacaste", "Puntarenas", "Limón")
provincias.current(0)
Direccion=tk.Label(modifEmpresa2, text="Dirección exacta", font=("Sans Serif", 12), width=15, height=2).place(x=150, y=270)
direccion=tk.Text(modifEmpresa2, width=35, height=6, font=("Sans Serif", 12))
direccion.place(x=61, y=320)
direccion.insert("1.0", UbicAntigua)
AgregarModif=tk.Button(modifEmpresa2, text="Modificar", font=("Sans Serif", 12), width=15, height=2, bg="grey", command=AgregarEmpresaModificada).place(x=150, y=500)
modifEmpresa2.mainloop()
def recopilarDatos(String): #Cada que la función se encuentre con un " | ", recopilará lo que esté antes de éste y lo almacena en una lista
if isinstance(String, str):
if String=="":
return []
else:
res=[]
sub=""
while String!="":
if String[0]!="|":
sub+=String[0]
String=String[1:]
else:
res+=[sub]
sub=""
String=String[1:]
return res+[sub]
ListaEmpresas=tk.Listbox(modifEmpresa, width=150)
ListaEmpresas.config(selectforeground="white",selectbackground="blue", selectborderwidth=3, font=("Sans Serif", 10))
barraY=tk.Scrollbar(modifEmpresa, command=ListaEmpresas.yview)
barraY.place(x=683, y=0, relheight=0.55)
ListaEmpresas.config(yscrollcommand=barraY)
barraX=tk.Scrollbar(modifEmpresa, command=ListaEmpresas.xview, orient=tk.HORIZONTAL)
barraX.place(x=0, y=217, relwidth=0.6)
ListaEmpresas.config(xscrollcommand=barraX)
ListaEmpresas.insert(0, "Cédula jurídica | Empresa | Ubicación |")
n=1
i=1
while info!=[]:
ListaEmpresas.insert(n, str(i)+") "+info[0]+"____")
info=info[1:]
n+=1
i+=1
ListaEmpresas.pack()
Emp=tk.Label(modifEmpresa, text="Empresa #", font=("Sans Serif", 12), bg="grey", width=15, height=2).pack(pady=2)
dato=tk.IntVar()
emp=tk.Entry(modifEmpresa, font="Helvetica 12", textvariable=dato)
emp.pack(pady=2)
seleccionar=tk.Button(modifEmpresa, text="Seleccionar", font=("Helvetica",14), bg="#6ee2ff", width="16",height="1",relief="groove", command=modifCamposEmpresa, cursor="hand2").pack(pady=2)
modifEmpresa.mainloop()
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
MostrarEmpresas
Como el nombre lo dice, sirve para mostrar las empresas
Entrada:
un botón (Mostrar Empresas)
Salida:
Muestra los datos del archivo'Empresas.txt'
"""
def MostrarEmpresas():
f=open("Empresas.txt", "r")
info=f.readlines()
f.close()
if info==[]:
mensaje=mb.showinfo(title="Atención", message="No hay empresas registradas")
return Empresas()
else:
verEmpresas=tk.Toplevel()
ancho_pantalla= 500
alto_pantalla= 400
#Porción de código para centrar la ventana a la pantalla
x_ventana=verEmpresas.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=verEmpresas.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
verEmpresas.geometry(posicion)
verEmpresas.title("Ver Empresas")
verEmpresas.iconbitmap("img.ico")
verEmpresas.config(bg="grey")
verEmpresas.resizable(0,1)
ListaEmpresas=tk.Listbox(verEmpresas, width=150)
ListaEmpresas.config(selectforeground="white",selectbackground="blue", selectborderwidth=3, font=("Sans Serif", 10))
barraY=tk.Scrollbar(verEmpresas, command=ListaEmpresas.yview)
barraY.place(x=483, y=0, relheight=0.55)
ListaEmpresas.config(yscrollcommand=barraY)
barraX=tk.Scrollbar(verEmpresas, command=ListaEmpresas.xview, orient=tk.HORIZONTAL)
barraX.place(x=0, y=217, relwidth=0.6)
ListaEmpresas.config(xscrollcommand=barraX)
ListaEmpresas.insert(0, "Cédula jurídica | Empresa | Ubicación |")
n=1
i=1
while info!=[]:
ListaEmpresas.insert(n, str(i)+") "+info[0]+"____")
info=info[1:]
n+=1
i+=1
ListaEmpresas.pack()
verEmpresas.mainloop()
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
GestionEmpresa.title("BestTraveller: Gestión de viajes")
GestionEmpresa.iconbitmap("img.ico")
imagen=tk.PhotoImage(file="f.png")
fondo=tk.Label(GestionEmpresa, image=imagen).place(x=0, y=0)
def volver():
GestionEmpresa.destroy()
return administrador()
label = tk.Label(GestionEmpresa, text="Gestor de Empresas", font=("Helvetica", 20, "italic", "bold"), bg="#6fafd8" ,relief="sunken").pack()
IncluirEmp=tk.Button(GestionEmpresa, text="Incluir Empresas", font=("Helvetica",14), bg="#6ee2ff", width="23",height="1",relief="groove", cursor="hand2", command=IncluirEmpresa).place(x=170, y=150)
BorrarEmp=tk.Button(GestionEmpresa, text="Borrar Empresas", font=("Helvetica",14), bg="#6ee2ff", width="23",height="1",relief="groove", cursor="hand2", command=BorrarEmpresas).place(x=170, y=200)
ModificarEmp=tk.Button(GestionEmpresa, text="Modificar Empresas", font=("Helvetica",14), bg="#6ee2ff", width="23",height="1",relief="groove", cursor="hand2", command=modificarEmpresas).place(x=170, y=250)
MostrarEmp=tk.Button(GestionEmpresa, text="Mostrar Empresas", font=("Helvetica",14), bg="#6ee2ff", width="23",height="1",relief="groove", cursor="hand2",command=MostrarEmpresas).place(x=170, y=300)
Volver=tk.Button(GestionEmpresa, text="Volver", command=volver, font=("Helvetica",14), bg="#6ee2ff", width="23",height="1",relief="groove", cursor="hand2").place(x=170, y=350)
GestionEmpresa.mainloop()
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
def Transportes(): #Ventana principal de las funciones de transportes
GestionTransporte= tk.Toplevel()
width= GestionTransporte.winfo_screenwidth()
height= GestionTransporte.winfo_screenheight()
GestionTransporte.geometry("%dx%d" % (width, height))
GestionTransporte.resizable(0,1)
#====================Funciones Auxiliares de gestión de Transportes====================#
"""
IncluirTransporte
Como el nombre lo dice, sirve para agregar un transporte a la base de datos
Entradas:
La placa
El tipo de transporte
Su marca
Modelo
Año
Empresa (Por Cédula)
Cantidad de asientos:
-VIP
-Normales
-Económicos
Salida:
Los datos obtenidos serán guardados en el archivo 'Transportes.txt'
Restricciones:
No pueden existir transportes con el mismo número de matrícula
"""
def IncluirTransporte():
nuevoTransporte=tk.Toplevel()
ancho_pantalla= 450
alto_pantalla= 600
#Porción de código para centrar la ventana a la pantalla
x_ventana=nuevoTransporte.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=nuevoTransporte.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
nuevoTransporte.geometry(posicion)
nuevoTransporte.title("Incluir Transporte")
nuevoTransporte.iconbitmap("img.ico")
nuevoTransporte.resizable(0,1)
Placa=tk.Label(nuevoTransporte, text="N° de matrícula", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=50)
placa=tk.IntVar()
datoPlaca=tk.Entry(nuevoTransporte, width=14, relief="sunken", textvariable=placa)
datoPlaca.place(x=200, y=64)
def contarDigitos(num):
if num==0:
return 1
else:
res=0
while num>0:
res+=1
num//=10
return res
def validarNuevoTransporte(): #Valida que la placa tenga 6 dígitos
numPlaca=datoPlaca.get()
if(contarDigitos(int(numPlaca))!=6):
error=tk.Label(nuevoTransporte, text="Error: El número de matrícula debe tener 6 dígitos", font=("Sans Serif", 10), width=41, height=1, fg="red").place(x=140, y=86)
else:
correcto=tk.Label(nuevoTransporte, text=" ", font=("Sans Serif", 10), width=41, height=1).place(x=140, y=86)
if(SeEncuentra("Transportes.txt", numPlaca)):
error=tk.Label(nuevoTransporte, text="Error: La placa ya se encuentra registrada", font=("Sans Serif", 10), width=32, height=1, fg="red").place(x=194, y=86)
else:
placa=str(datoPlaca.get())
tipo=str(datoTipo.get())
Marca=str(marca.get())
Modelo=str(modelo.get())
Año=str(año.get())
empresa=str(ElegirEmpresa.get())
aVIP=str(VIP.get())
aNORMAL=str(NORMAL.get())
aECONOM=str(ECONOM.get())
filas=str(Filas.get())
f=open("Transportes.txt", "a")
f.write(placa+"|"+tipo+"|"+Marca+"|"+Modelo+"|"+Año+"|"+empresa+"|"+aVIP+"-"+aNORMAL+"-"+aECONOM+"|"+filas+"\n")
f.close()
f = open ("Asientos.txt",'a')
f.write(placa+"|"+aVIP+"|"+aNORMAL+"|"+aECONOM+"|"+filas+"\n")
f.close()
hecho=mb.showinfo(title="Información", message="El transporte se agregó exitosamente")
nuevoTransporte.destroy()
return Transportes()
"""
SeEncuentra
E: un archivo y una palabra para buscarla en el archivo
S: Si la palabra se encuentra en el archivo, retornará True, sino False
"""
def SeEncuentra(archivo, palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista): #f.readlines convierte el texto a lista
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return False
else:
return buscarAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return True
Tipo=tk.Label(nuevoTransporte, text="Tipo de vehículo", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=110)
datoTipo=tk.Entry(nuevoTransporte, relief="sunken", font=("Sans Serif", 12))
datoTipo.place(x=200, y=126)
Marca=tk.Label(nuevoTransporte, text= "Marca", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=150)
marca=tk.Entry(nuevoTransporte, font=("Sans Serif", 12))
marca.place(x=200, y=166)
Modelo=tk.Label(nuevoTransporte, text= "Modelo", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=193)
modelo=tk.Entry(nuevoTransporte, font=("Sans Serif", 12))
modelo.place(x=200, y=206)
Año=tk.Label(nuevoTransporte, text= "Año", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=230)
año=tk.Entry(nuevoTransporte, font=("Sans Serif", 12))
año.place(x=200, y=243)
Empresa=tk.Label(nuevoTransporte, text= "Empresa", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=268)
ElegirEmpresa=ttk.Combobox(nuevoTransporte)
ElegirEmpresa.place(x=200, y=280)
f=open("Empresas.txt", "r")
lineas=f.readlines()
f.close()
if lineas==[]:
error=mb.showerror(title="Error", message="No hay empresas registradas en el sistema\n No se puede proceder")
nuevoTransporte.destroy()
return Transportes()
else:
empresas=[]
while lineas!=[]:
empresas+=[str(lineas[0])[:10]]
lineas=lineas[1:]
ElegirEmpresa["values"]=empresas
ElegirEmpresa.current(0)
Asientos=tk.Label(nuevoTransporte, text="-------------Asientos-------------", font=("Sans Serif", 12), width=35, height= 2).place(x=55, y=301)
vip=tk.Label(nuevoTransporte, text="VIP", font=("Sans Serif", 12), width=10, height= 2).place(x=11, y=354)
VIP=tk.Entry(nuevoTransporte, font=("Sans Serif", 12), width=8)
VIP.place(x=18, y=390)
normal=tk.Label(nuevoTransporte, text="Normales", font=("Sans Serif", 12), width=10, height= 2).place(x=167, y=354)
NORMAL=tk.Entry(nuevoTransporte, font=("Sans Serif", 12), width=8)
NORMAL.place(x=177, y=390)
econom=tk.Label(nuevoTransporte, text="Económicos", font=("Sans Serif", 12), width=10, height= 2).place(x=320, y=354)
ECONOM=tk.Entry(nuevoTransporte, font=("Sans Serif", 12), width=8)
ECONOM.place(x=330, y=390)
filas=tk.Label(nuevoTransporte, text="Asientos por fila", font=("Sans Serif", 12), width=15, height= 2).place(x=147, y=410)
Filas=tk.Entry(nuevoTransporte, font=("Sans Serif", 12), width=8)
Filas.place(x=177, y=450)
validacion=tk.Button(nuevoTransporte, text="Validar", font=("Sans Serif", 12), width=15, height=2, bg="grey", command=validarNuevoTransporte).place(x=150, y=500)
nuevoTransporte.mainloop()
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
BorrarTransportes
Dada la cédula de una empresa, elimina la empresa que esté vinculada con dicha cédula
E: la cédula
S: Borra la empresa del archivo 'Empresas.txt'
R: No puede borrarse aquella empresa que esté vinculada a un transporte
"""
def BorrarTransportes():
borrartransporte= tk.Tk()
borrartransporte.title("Borrar empresa")
ancho_pantalla= 400
alto_pantalla= 120
#Porción de código para centrar la ventana a la pantalla
x_ventana=borrartransporte.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=borrartransporte.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
borrartransporte.geometry(posicion)
borrartransporte.resizable(0,1)
borrartransporte.iconbitmap("img.ico")
"""
buscarPalabra
E: un archivo y una palabra para buscarla en el archivo
S: Si la palabra se encuentra en el archivo, retornará la línea en la cual está ubicada
"""
def buscarPalabra(archivo,palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarPalabraAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista):
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarPalabraAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return "Sin resultados"
else:
return buscarPalabraAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarPalabraAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarPalabraAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarPalabraAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return res
"""
BorrarLinea
Dada una palabra clave, borra una linea de un archivo en la cual se encuentra dicha palabra:
"""
def borrarLinea():
identif=transporte.get()
lineaAborrar=buscarPalabra("Transportes.txt", identif)
AsientosABorrar=buscarPalabra("Asientos.txt", identif)
if lineaAborrar=="Sin resultados":
info=mb.showerror(title="Error en entrada", message="No se encontraron coincidencias")
borrartransporte.destroy()
return BorrarTransportes()
if(SeEncuentra("Viajes.txt", identif)):
info=mb.showerror(title="Error en entrada", message="No se puede borrar.\nEl transporte se encuentra registrado en un viaje")
borrartransporte.destroy()
return Transportes()
else:
f = open("Transportes.txt","r")
lineas = f.readlines()
f.close()
g=open("Asientos.txt", "r")
asientos=g.readlines()
g.close()
f = open("Transportes.txt","w")
g=open("Asientos.txt", "w")
while lineas!=[]:
if lineas[0]!=lineaAborrar:
g.write(asientos[0])
f.write(lineas[0])
lineas=lineas[1:]
asientos=asientos[1:]
else:
asientos=asientos[1:]
lineas=lineas[1:]
f.close()
g.close()
info=mb.showinfo(title="Estado", message="El transporte se eliminó exitosamente")
borrartransporte.destroy()
return Transportes()
def SeEncuentra(archivo, palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista): #f.readlines convierte el texto a lista
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return False
else:
return buscarAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return True
label=tk.Label(borrartransporte, text="Digite el número de matrícula a borrar", font=("Sans serif", 14)).pack()
transporte=tk.Entry(borrartransporte, font="Helvetica 12")
transporte.pack()
borrar=tk.Button(borrartransporte, text="Borrar", font=("Helvetica",14), bg="#6ee2ff", width="16",height="1",relief="groove", command=borrarLinea, cursor="hand2").pack()
borrartransporte.mainloop()
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
ModificarTransportes
Se selecciona un transporte de la lista de transportes, para posteriormente modificar sus campos
Entrada:
el transporte seleccionada (Se selecciona por posición y se modifican todos sus campos, exceptuando la placa)
Salida:
Los cambios se registrarán en el archivo 'Transportes.txt'
"""
def modificarTransportes():
f=open("Transportes.txt", "r")
info=f.readlines()
f.close()
if info==[]:
mensaje=mb.showinfo(title="Atención", message="No hay transportes registrados")
return Transportes()
else:
modifTransporte=tk.Toplevel()
ancho_pantalla= 700
alto_pantalla= 400
#Porción de código para centrar la ventana a la pantalla
x_ventana=modifTransporte.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=modifTransporte.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
modifTransporte.geometry(posicion)
modifTransporte.title("Ver Transportes")
modifTransporte.iconbitmap("img.ico")
modifTransporte.config(bg="grey")
modifTransporte.resizable(0,1)
def modifCamposTransporte():
num=int(trp.get())
Datos=ListaTransportes.get(num)
PlacaVHC=Datos[3:9]
RestoDeDatos=recopilarDatos(Datos[10:-4])
TipoAntiguo=RestoDeDatos[0]
MarcaAntigua=RestoDeDatos[1]
ModeloAntiguo=RestoDeDatos[2]
AñoAntiguo=RestoDeDatos[3]
VIPAntiguo=RestoDeDatos[5]
NormalAntiguo=RestoDeDatos[6]
EconomAntiguo=RestoDeDatos[7]
modifTransporte.destroy()
return modifCamposTransporteAux(PlacaVHC, TipoAntiguo, MarcaAntigua, ModeloAntiguo, AñoAntiguo, VIPAntiguo, NormalAntiguo, EconomAntiguo)
def modifCamposTransporteAux(PlacaVHC, TipoAntiguo, MarcaAntigua, ModeloAntiguo, AñoAntiguo, VIPAntiguo, NormalAntiguo, EconomAntiguo):
modifTransporte2=tk.Toplevel()
ancho_pantalla= 450
alto_pantalla= 600
#Porción de código para centrar la ventana a la pantalla
x_ventana=modifTransporte2.winfo_screenwidth() // 2 - ancho_pantalla // 2
y_ventana=modifTransporte2.winfo_screenheight() // 2 - alto_pantalla // 2
posicion=str(ancho_pantalla)+"x"+str(alto_pantalla)+"+"+str(x_ventana)+"+"+str(y_ventana)
modifTransporte2.geometry(posicion)
modifTransporte2.title("Modificar transporte")
modifTransporte2.iconbitmap("img.ico")
modifTransporte2.resizable(0,1)
Placa=tk.Label(modifTransporte2, text="N° de matrícula", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=50)
datoPlaca=tk.Entry(modifTransporte2, width=14, relief="sunken")
datoPlaca.place(x=200, y=64)
datoPlaca.insert(0, PlacaVHC)
datoPlaca.config(state=tk.DISABLED)
def AgregarTransporteModificado(): #Función para agregar el transporte modificado
Placa=str(datoPlaca.get())
tipo=str(datoTipo.get())
Nuevamarca=str(marca.get())
Nuevomodelo=str(modelo.get())
nuevoAño=str(año.get())
NuevaEmp=str(ElegirEmpresa.get())
NuevoVIP=str(VIP.get())
NuevoNormal=str(NORMAL.get())
NuevoEconom=str(ECONOM.get())
filas=str(Filas.get())
lineaAmodificar=buscarPalabra("Transportes.txt", Placa)
asientosAmodificar=buscarPalabra("Asientos.txt", Placa)
f = open("Transportes.txt","r")
lineas = f.readlines()
f.close()
g=open("Asientos.txt", "r")
asientos = g.readlines()
g.close()
f = open("Transportes.txt","w")
g=open("Asientos.txt", "w")
while lineas!=[]:
if lineas[0]!=lineaAmodificar:
f.write(lineas[0])
g.write(asientos[0])
lineas=lineas[1:]
asientos=asientos[1:]
else:
f.write(Placa+"|"+tipo+"|"+Nuevamarca+"|"+Nuevomodelo+"|"+nuevoAño+"|"+NuevaEmp+"|"+NuevoVIP+"-"+NuevoNormal+"-"+NuevoEconom+"|"+filas)
g.write(Placa+"|"+NuevoVIP+"|"+NuevoNormal+"|"+NuevoEconom+"|"+filas)
lineas=lineas[1:]
asientos=asientos[1:]
f.close()
g.close()
info=mb.showinfo(title="Estado", message="El transporte se modificó exitosamente")
modifTransporte2.destroy()
return Transportes()
def buscarPalabra(archivo,palabra):
archivo=open(archivo, "r")
contexto= archivo.readlines()
archivo.close()
Datos=contarObjetos(contexto)
largoPalabra=contarString(palabra)
return buscarPalabraAux(palabra, contexto, Datos, largoPalabra)
def contarObjetos(lista):
n=0
while lista!=[]:
n+=1
lista=lista[1:]
return n
def contarString(texto):
res=0
while texto!="":
res+=1
texto=texto[1:]
return res
def buscarPalabraAux(palabra, contexto, Datos, largoPalabra):
if Datos==0:
return "Sin resultados"
else:
return buscarPalabraAux2(palabra, contexto, contexto[0], Datos, largoPalabra, contarString(contexto[0]), contexto[0])
def buscarPalabraAux2(palabra, contexto, texto, Datos, largoPalabra, i, res):
if i<largoPalabra:
return buscarPalabraAux(palabra, contexto[1:], Datos-1, largoPalabra)
else:
while palabra!=texto[:largoPalabra]:
return buscarPalabraAux2(palabra, contexto, texto[1:], Datos, largoPalabra, i-1, res)
return res
Tipo=tk.Label(modifTransporte2, text="Tipo de vehículo", font=("Sans Serif", 12), width=25, height=2). place(x=0, y=110)
datoTipo=tk.Entry(modifTransporte2, relief="sunken", font=("Sans Serif", 12))
datoTipo.place(x=200, y=126)
datoTipo.insert(0, TipoAntiguo)
Marca=tk.Label(modifTransporte2, text= "Marca", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=150)
marca=tk.Entry(modifTransporte2, font=("Sans Serif", 12))
marca.place(x=200, y=166)
marca.insert(0, MarcaAntigua)
Modelo=tk.Label(modifTransporte2, text= "Modelo", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=193)
modelo=tk.Entry(modifTransporte2, font=("Sans Serif", 12))
modelo.place(x=200, y=206)
modelo.insert(0, ModeloAntiguo)
Año=tk.Label(modifTransporte2, text= "Año", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=230)
año=tk.Entry(modifTransporte2, font=("Sans Serif", 12))
año.place(x=200, y=243)
año.insert(0, AñoAntiguo)
Empresa=tk.Label(modifTransporte2, text= "Empresa", font=("Sans Serif", 12),width=25, height=2).place(x=0,y=268)
ElegirEmpresa=ttk.Combobox(modifTransporte2)
ElegirEmpresa.place(x=200, y=280)
f=open("Empresas.txt", "r")
lineas=f.readlines()
f.close()
empresas=[]
while lineas!=[]:
empresas+=[str(lineas[0])[:10]]
lineas=lineas[1:]
ElegirEmpresa["values"]=empresas
ElegirEmpresa.current(0)
Asientos=tk.Label(modifTransporte2, text="-------------Asientos-------------", font=("Sans Serif", 12), width=35, height= 2).place(x=55, y=301)
vip=tk.Label(modifTransporte2, text="VIP", font=("Sans Serif", 12), width=10, height= 2).place(x=11, y=354)
VIP=tk.Entry(modifTransporte2, font=("Sans Serif", 12), width=8)
VIP.place(x=18, y=390)
VIP.insert(0, VIPAntiguo)
normal=tk.Label(modifTransporte2, text="Normales", font=("Sans Serif", 12), width=10, height= 2).place(x=167, y=354)
NORMAL=tk.Entry(modifTransporte2, font=("Sans Serif", 12), width=8)
NORMAL.place(x=177, y=390)
NORMAL.insert(0, NormalAntiguo)
econom=tk.Label(modifTransporte2, text="Económicos", font=("Sans Serif", 12), width=10, height= 2).place(x=320, y=354)
ECONOM=tk.Entry(modifTransporte2, font=("Sans Serif", 12), width=8)
ECONOM.place(x=330, y=390)
ECONOM.insert(0, EconomAntiguo)
filas=tk.Label(modifTransporte2, text="Asientos por fila", font=("Sans Serif", 12), width=15, height= 2).place(x=147, y=410)
Filas=tk.Entry(modifTransporte2, font=("Sans Serif", 12), width=8)
Filas.place(x=177, y=450)