Python - SUMATORIA DE NUMEROS ENTEROS CON SEPARADORES DE MILES..

 
Vista:
sin imagen de perfil
Val: 37
Ha disminuido su posición en 8 puestos en Python (en relación al último mes)
Gráfica de Python

SUMATORIA DE NUMEROS ENTEROS CON SEPARADORES DE MILES..

Publicado por PENNELOPPE (14 intervenciones) el 24/08/2020 18:31:30
buenas tardes Sres del foro antes que todo un gran saludo me dirijo a usted con la finalidad de que me de una orientacion , como hago cuando estoy introducion numeros enteros en un entry() en progamacion python que a medida que voy introduccion los numeros me poga los separadores de miles automaticamente y que cuando yo sume los numeros introducidos en los dos entry() me lo sumes y ponga los separadores de miles. necesito una gran orientacion lo antes posibles este es la codificacion que he hecho:
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
from tkinter import *
from tkinter import messagebox
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import sqlite3
from tkinter import ttk
from tabulate import *
import wx
import wx.grid as wxgrid
import itertools
from random import randint
from statistics import mean
from datetime import datetime
from datetime import date
import locale
 
 
# ------------- INTERFACES GRAFICAS -----------
 
 
inicio1 = Tk()
inicio1.title("CUENTAS CONTABLES")
inicio1.resizable(0,0)
inicio1.iconbitmap("contabilidad.ico")
miimag = PhotoImage(file = "registro1.png")
miimag1 = PhotoImage(file = "SALIR.png")
miimag2 = PhotoImage(file = "ADDIC.png")
miimag3 = PhotoImage(file = "reportes1.png")
miimag4 = PhotoImage(file = "eliminardoc.png")
 
inicio1.config(bg = "MediumSlateBlue", bd = 25, relief = "groove", cursor ="diamond_cross")
 
miframe1 = Frame(inicio1)
miframe1.config(bg = "MediumPurple",bd = 35, relief = "ridge")
miframe1.pack(anchor = "sw", fill= "x", expand = 1)
miframe3 = Frame(inicio1)
miframe3.config(bg = "MediumPurple",bd = 35, relief = "ridge")
miframe3.pack(anchor = "sw", fill= "x", expand = 1)
 
 
#------------ FUNCION SALIR DEL SISTEMA -------------
 
def salirsys():
	valor1 = messagebox.askokcancel("SALIR..","DESEA SALIR DEL SYSTEM?")
	if valor1 == True:
		inicio1.destroy()
 
#------------ FUNCION SUMA --------------------------
def  sumatot():
	locale.setlocale(locale.LC_ALL, '')
	print(int(debebal.get()))
	print(int(haberbal.get()))
	sumaux = debebal.get() + haberbal.get()
	totalsuma.set(sumaux)
 
#------------ CONJUNTOS DE INTERFAZ------------------
 
totalsuma = IntVar()
totalsuma.set(0)
fechaac = date.today()
fecha = fechaac.strftime("%B %Y")
fechabal = StringVar()
fecha1 = fechaac.strftime("%d/%m/%y")
fechabal.set(fecha1)
debebal = IntVar()
locale.setlocale(locale.LC_ALL, '')
debebal.set(locale.format_string('%10d', 600000, grouping=True))
haberbal = IntVar()
haberbal.set(locale.format_string('%10d', 400000, grouping=True))
descrip2 = Label(miframe1, text = "FECHA: ", fg = "MidnightBlue", font = ("Comic Sans MS", 10))
descrip2.config(bg="MediumPurple")
descrip2.grid(row = 0, column = 0,sticky = "w",padx = 15,pady = 5)
descrip2text = Entry(miframe1,fg = "Blue", font = ("Comic Sans MS",10), width = 50,textvariable = fechabal)
descrip2text.grid(row = 0, column = 1,sticky = "w",padx = 15,pady = 5)
codigop2p = Label(miframe1, text = "DEBE: ", fg = "MidnightBlue", font = ("Comic Sans MS", 10))
codigop2p.config(bg="MediumPurple")
codigop2p.grid(row = 1, column = 0,sticky = "w",padx = 15,pady = 5)
descrip2text = Entry(miframe1,fg = "Blue", font = ("Comic Sans MS",10), width = 50,textvariable = debebal)
descrip2text.grid(row = 1, column = 1,sticky = "w",padx = 15,pady = 5)
codigop2p = Label(miframe1, text = "HABER: ", fg = "MidnightBlue", font = ("Comic Sans MS", 10))
codigop2p.config(bg="MediumPurple")
codigop2p.grid(row = 2, column = 0,sticky = "w",padx = 15,pady = 5)
descrip2text = Entry(miframe1,fg = "Blue", font = ("Comic Sans MS",10), width = 50,textvariable = haberbal)
descrip2text.grid(row = 2, column = 1,sticky = "w",padx = 15,pady = 5)
codigop2 = Label(miframe1, text = "TOTAL: ", fg = "MidnightBlue", font = ("Comic Sans MS", 10))
codigop2.config(bg="MediumPurple")
codigop2.grid(row = 3, column = 0,sticky = "w",padx = 15,pady = 5)
codigop2text = Entry(miframe1,fg = "Blue", font = ("Comic Sans MS",10), width = 50, textvariable = totalsuma)
codigop2text.grid(row = 3, column = 1,sticky = "w",padx = 15,pady = 5)
 
 
#------------- BOTON DE CONECCION , ENTRADA Y SALIDA -------------
 
crearbotton5 = Button(miframe3, text = "SUMAR CUENTAS", fg = "MidnightBlue", font = ("Comic Sans MS",10, "bold"),
     anchor = CENTER, image = miimag3, compound = CENTER, command = sumatot)
crearbotton5.config(bg = "LightCyan",bd = 15, relief = "ridge")
crearbotton5.grid(row = 0, column = 0,sticky = "w",padx = 15,pady = 5)
salirbotton = Button(miframe3, text = "SALIR", fg = "MidnightBlue", font = ("Comic Sans MS",10, "bold"),
	anchor = CENTER, image = miimag1, compound = CENTER, command = salirsys)
salirbotton.config(bg = "LightCyan",bd = 15, relief = "ridge")
salirbotton.grid(row = 0, column = 3,sticky = "w",padx = 15,pady = 5)
 
inicio1.mainloop()

y el resultado que me da es este al ver la imagen se da cuenta que al darle al boton de suma me da 1000 y no 1.ooo.ooo y cuando le doy print a las variales.get() observo que me quita los tres ceros despues del punto la coniguracion de los numeros es de aqui de venezuela que los separadores son con puntos.



PREGUNTA1

PREGUNTA2
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

SUMATORIA DE NUMEROS ENTEROS CON SEPARADORES DE MILES..

Publicado por yoyyo (1 intervención) el 25/08/2020 11:04:01
hola:
en principio no me gusta usar locale, no necesariamente todos tienen la misma configuración y al usar las variables como int permiten menos manipulación de formato, así que lo haría de esta otra forma, es más simple crear un código nuevo que ponerme a corregir el tuyo.
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
from tkinter import *
 
def sumar():
    sumaux = int(sumar1.get().replace(".","")) + int(sumar2.get().replace(".",""))
    total_res.set("{:,}".format(sumaux).replace(",","."))
 
ventana = Tk()
sumar1=StringVar()
sumar2=StringVar()
total_res=StringVar()
total_res.set(0)
 
entrada1=Entry(ventana,textvariable=sumar1)
entrada1.pack()
sumar1.set("{:,}".format(600000).replace(",","."))
entrada2=Entry(ventana,textvariable=sumar2)
sumar2.set("{:,}".format(400000).replace(",","."))
entrada2.pack()
 
 
boton = Button(ventana,text="sumar",command=sumar)
boton.pack()
 
total=Entry(ventana,textvariable=total_res)
total.pack()
ventana.mainloop()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 37
Ha disminuido su posición en 8 puestos en Python (en relación al último mes)
Gráfica de Python

SUMATORIA DE NUMEROS ENTEROS CON SEPARADORES DE MILES..

Publicado por PENNELOPPE (14 intervenciones) el 25/08/2020 17:35:19
MIL GRACIAS YOYYO POR SU GRAN AYUDA ME FUNCIONO ES VERDAD TRABAJAR CON FORMATO ES UN POCO COMPLICADO PORQUE COMO USTED OBSERVO CUANDO YO LE HACIA U PRINT AL VARIABLE DEBEBAL.GET() Y HABERBAL.GET() OBSERVABA QUE QUITABA LOS TRES CEROS DESPUES DEL PUNTO Y ESO QUE EN LA CAJA DE TEXTO ENTRY() ME LO MOSTRABA PERO AL HACER LA SUMA CUANDO HACIA UN GET() LE QUITABA LOS TRES CERO Y POR ESO NO DABA LA SUMA TOTAL
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