Am using Python 3.7 when a user enters a number, he expects to see the figure displayed in the entry field with commas.
eg 3755125.70 to be displayed as 3,755,125.70. Is it possible?
5 3659 - f = float(input())
-
print('{:,}'.format(f))
Please is it possible to be part of the Entry options python?
eg FloatNumber=Entry(textvariable = f, ('{:,}'.format(f))
thanks
For your solution, the following code will work : -
from tkinter import *
-
import locale
-
root = Tk()
-
-
FloatNumber = float(input('Enter no : '))
-
b = Entry(root, textvariable = FloatNumber, justify = RIGHT).pack()
-
-
def getOutput(*events):
-
x = FloatNumber.get()
-
y = x.replace(",",'')
-
z = float(y)
-
print(z)
-
try:
-
asd = format(z,',')
-
print(asd)
-
except:
-
print("b")
-
#Overwrite the Entrybox content using the widget's own methods
-
b.delete(0, END)
-
b.insert(0, asd)
-
-
FloatNumber.trace('w',getOutput)
-
root.mainloop()
-
import locale
>>> locale.setlocale(locale.LC_ALL, 'en_US')
'en_US'
>>> locale.format("%d", 3755125, grouping=True)
'3,755,125'
In this method, the part after the colon is the format specifier. The comma is the separator character you want,
This is equivalent of using format(num, ",d") for older versions of python.
we can use my_string = '{:,. 2f}'. format(my_number) to convert float value into commas as thousands separators.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jive |
last post by:
Here's my sitch:
I use gnuplot.py at work, platform Win32. I want to upgrade to Python 2.4.
Gnuplot.py uses extension module Numeric. Numeric is now "unsupported."
The documentation says "If...
|
by: Cedric |
last post by:
This is a 3 weeks old problem, but having found a solution (and having
looked for one here, finding only this message), I'm replying now.
From: Jive (someone@microsoft.com)
Subject: Upgrade...
|
by: Mark |
last post by:
I have a Decimal or a Double - your choice. I'd like to print the number as
string with a specified number of decimal places. Let's say my number
110.5, and I'd like to capture it in a string...
|
by: Mike Moore |
last post by:
We would like to use a validator to valid that only numeric data is allowed
in a text box. Is there a way to do this? If so, how?
|
by: Dustan |
last post by:
Earlier I asked about limitting what a user can enter in an Entry. I
got a few greatly appreciated replies, but I was hoping it would be
possible to take a more direct approach, that is, is there a...
|
by: Netmonster |
last post by:
All,
How to format string add commas at thousands position, and hundred
thousands position
Example 1: I have string s = "1001"; or could be a random number I want
the output to be 1,001.
...
|
by: JP SIngh |
last post by:
Hi All
We are creating a multi-region ASP application which will be using SQL
Server 2000.
As our users exist in multiple location i.e. UK, US, Australia how can we
distinguish that the date...
|
by: libsfan01 |
last post by:
how can i use regular expressions to ensure a mysql format date entry
in a text field?
thanks
marc
|
by: John |
last post by:
I am coding a radix sort in python and I think that Python's dictionary may
be a choice for bucket.
The only problem is that dictionary is a mapping without order. But I just
found that if the...
|
by: Earl G via AccessMonster.com |
last post by:
I have tried. But now I ask. I cannot get a control to accept a numeric
entry (e.g. 0.23) without first entering a zero. I want to allow only two
decimal places. But I would like numbers less...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |