Big Number Calculator (human readable format)











up vote
3
down vote

favorite












I'm looking for a calculator suitable for large numbers where a letter can be entered instead of a whole bunch of zeros:




  • K (Kilo) 000


  • M (Mega) 000,000 .............................. Million


  • G (Giga) 000,000,000 ....................... Billion


  • T (Tera) 000,000,000,000 ............... Trillion


  • P (Peta) 000,000,000,000,000 ........ Quadtrillion


  • E (Exa) 000,000,000,000,000,000 . Quintrillion


For example $20 trillion dollars / 50 million units would be entered as:



20t / 50m


The result is 400,000 and can be displayed as 400 K.



Is there already a calculator for Ubuntu / Debian for Big Numbers (aka Human Readable format)?



My question is similar to these questions but not a duplicate:




  • Add thousand separator to gnome calculator in Ubuntu 18.04

  • How to show comma seperation in numbers on ubuntu's calculator?


The letters used such as T for Tera (Trillion) or G for Giga (Billion), etc. come from industry standards. Standards are set by Institute of Electrical and Electronics Engineers (IEEE).





Edit: A few days after original question was posted, this turned into a self-answered question. Original answers though and alternative suggestions are welcome and would likely interest others.










share|improve this question




























    up vote
    3
    down vote

    favorite












    I'm looking for a calculator suitable for large numbers where a letter can be entered instead of a whole bunch of zeros:




    • K (Kilo) 000


    • M (Mega) 000,000 .............................. Million


    • G (Giga) 000,000,000 ....................... Billion


    • T (Tera) 000,000,000,000 ............... Trillion


    • P (Peta) 000,000,000,000,000 ........ Quadtrillion


    • E (Exa) 000,000,000,000,000,000 . Quintrillion


    For example $20 trillion dollars / 50 million units would be entered as:



    20t / 50m


    The result is 400,000 and can be displayed as 400 K.



    Is there already a calculator for Ubuntu / Debian for Big Numbers (aka Human Readable format)?



    My question is similar to these questions but not a duplicate:




    • Add thousand separator to gnome calculator in Ubuntu 18.04

    • How to show comma seperation in numbers on ubuntu's calculator?


    The letters used such as T for Tera (Trillion) or G for Giga (Billion), etc. come from industry standards. Standards are set by Institute of Electrical and Electronics Engineers (IEEE).





    Edit: A few days after original question was posted, this turned into a self-answered question. Original answers though and alternative suggestions are welcome and would likely interest others.










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I'm looking for a calculator suitable for large numbers where a letter can be entered instead of a whole bunch of zeros:




      • K (Kilo) 000


      • M (Mega) 000,000 .............................. Million


      • G (Giga) 000,000,000 ....................... Billion


      • T (Tera) 000,000,000,000 ............... Trillion


      • P (Peta) 000,000,000,000,000 ........ Quadtrillion


      • E (Exa) 000,000,000,000,000,000 . Quintrillion


      For example $20 trillion dollars / 50 million units would be entered as:



      20t / 50m


      The result is 400,000 and can be displayed as 400 K.



      Is there already a calculator for Ubuntu / Debian for Big Numbers (aka Human Readable format)?



      My question is similar to these questions but not a duplicate:




      • Add thousand separator to gnome calculator in Ubuntu 18.04

      • How to show comma seperation in numbers on ubuntu's calculator?


      The letters used such as T for Tera (Trillion) or G for Giga (Billion), etc. come from industry standards. Standards are set by Institute of Electrical and Electronics Engineers (IEEE).





      Edit: A few days after original question was posted, this turned into a self-answered question. Original answers though and alternative suggestions are welcome and would likely interest others.










      share|improve this question















      I'm looking for a calculator suitable for large numbers where a letter can be entered instead of a whole bunch of zeros:




      • K (Kilo) 000


      • M (Mega) 000,000 .............................. Million


      • G (Giga) 000,000,000 ....................... Billion


      • T (Tera) 000,000,000,000 ............... Trillion


      • P (Peta) 000,000,000,000,000 ........ Quadtrillion


      • E (Exa) 000,000,000,000,000,000 . Quintrillion


      For example $20 trillion dollars / 50 million units would be entered as:



      20t / 50m


      The result is 400,000 and can be displayed as 400 K.



      Is there already a calculator for Ubuntu / Debian for Big Numbers (aka Human Readable format)?



      My question is similar to these questions but not a duplicate:




      • Add thousand separator to gnome calculator in Ubuntu 18.04

      • How to show comma seperation in numbers on ubuntu's calculator?


      The letters used such as T for Tera (Trillion) or G for Giga (Billion), etc. come from industry standards. Standards are set by Institute of Electrical and Electronics Engineers (IEEE).





      Edit: A few days after original question was posted, this turned into a self-answered question. Original answers though and alternative suggestions are welcome and would likely interest others.







      software-recommendation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago

























      asked Dec 5 at 1:38









      WinEunuuchs2Unix

      41.5k1070158




      41.5k1070158






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          An initial solution only took a few minutes by taking this readily available Python Calculator GUI.





          Add a little code



          The full script is below but to summarize insert these lines near the top:



          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')


          Insert these lines near the bottom:



            Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)


          Insert these lines in the middle:



           def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]


          There are a few other cosmetic changes for larger font on HDPI monitor (1920x1080 pixels)



          Sample Calculator Window



          calc.py.png




          • This is a pretty standard calculator layout.

          • Notice the bottom row of keys we added.

          • You can click the keys or simply type in T instead of clicking T button.

          • Also notice how we entered 20 t / 50 M to represent 20 Trillion divided by 50 Million.

          • The result will be displayed as 400 K


          Full Python Script



          #-*-coding: utf-8-*-
          # NAME: calc.py
          # CALL: python calc.py
          # DATE: December 8, 2018
          # DESC: Calculator in E-Exa, P-Peta, T-Tetra, G-Giga, M-Mega and K-Kilo
          # NOTE: Requires Tkinter GUI libraries: sudo apt install python-tk

          # Majority Credit to: https://www.techinfected.net/2016/02/make-gui-calculator-in-python-windows-linux.html
          from Tkinter import *
          import tkFont
          import math

          class calc:
          def getandreplace(self):
          """replace x with * and ÷ with /"""

          self.expression = self.e.get()
          self.newtext=self.expression.replace(self.newdiv,'/')
          self.newtext=self.newtext.replace('x','*')
          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')

          def equals(self):
          """when the equal button is pressed"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.e.delete(0,END)
          self.value= self.convert() # Give result in K, M, G, T, P or E
          self.e.insert(0,self.value)

          def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]

          def squareroot(self):
          """squareroot method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqrtval=math.sqrt(self.value)
          self.e.delete(0,END)
          self.e.insert(0,self.sqrtval)

          def square(self):
          """square method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqval=math.pow(self.value,2)
          self.e.delete(0,END)
          self.e.insert(0,self.sqval)

          def clearall(self):
          """when clear button is pressed,clears the text input area"""
          self.e.delete(0,END)

          def clear1(self):
          self.txt=self.e.get()[:-1]
          self.e.delete(0,END)
          self.e.insert(0,self.txt)

          def action(self,argi):
          """pressed button's value is inserted into the end of the text area"""
          self.e.insert(END,argi)

          def __init__(self,master):
          """Constructor method"""
          master.title('Calculator')
          master.geometry()
          font = "Calibri 13"
          self.e = Entry(master, font = "Calibri 13")
          # self.e = Entry(master)
          self.e.grid(row=0,column=0,columnspan=6,pady=3)
          self.e.focus_set() #Sets focus on the input text area

          self.div='÷'
          self.newdiv=self.div.decode('utf-8')

          #Generating Buttons
          # Button(master,text="=",width=10,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text="=",width=8,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text='AC',width=3,command=lambda:self.clearall()).grid(row=1, column=4)
          Button(master,text='C',width=3,command=lambda:self.clear1()).grid(row=1, column=5)
          Button(master,text="+",width=3,command=lambda:self.action('+')).grid(row=4, column=3)
          Button(master,text="x",width=3,command=lambda:self.action('x')).grid(row=2, column=3)
          Button(master,text="-",width=3,command=lambda:self.action('-')).grid(row=3, column=3)
          Button(master,text="÷",width=3,command=lambda:self.action(self.newdiv)).grid(row=1, column=3)
          Button(master,text="%",width=3,command=lambda:self.action('%')).grid(row=4, column=2)
          Button(master,text="7",width=3,command=lambda:self.action('7')).grid(row=1, column=0)
          Button(master,text="8",width=3,command=lambda:self.action(8)).grid(row=1, column=1)
          Button(master,text="9",width=3,command=lambda:self.action(9)).grid(row=1, column=2)
          Button(master,text="4",width=3,command=lambda:self.action(4)).grid(row=2, column=0)
          Button(master,text="5",width=3,command=lambda:self.action(5)).grid(row=2, column=1)
          Button(master,text="6",width=3,command=lambda:self.action(6)).grid(row=2, column=2)
          Button(master,text="1",width=3,command=lambda:self.action(1)).grid(row=3, column=0)
          Button(master,text="2",width=3,command=lambda:self.action(2)).grid(row=3, column=1)
          Button(master,text="3",width=3,command=lambda:self.action(3)).grid(row=3, column=2)
          Button(master,text="0",width=3,command=lambda:self.action(0)).grid(row=4, column=0)
          Button(master,text=".",width=3,command=lambda:self.action('.')).grid(row=4, column=1)
          Button(master,text="(",width=3,command=lambda:self.action('(')).grid(row=2, column=4)
          Button(master,text=")",width=3,command=lambda:self.action(')')).grid(row=2, column=5)
          Button(master,text="√",width=3,command=lambda:self.squareroot()).grid(row=3, column=4)
          Button(master,text="x²",width=3,command=lambda:self.square()).grid(row=3, column=5)
          Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)
          #Main
          root = Tk()
          # Larger font for HDPI screen
          default_font = tkFont.nametofont("TkDefaultFont")
          default_font.configure(size=11)
          obj=calc(root) #object instantiated
          root.mainloop()


          Many thanks to the author (on first link above) for contributing this code!



          Install Tkinter



          You need python-tk (Tkinter) installed to use Python GUI Calculator:



          sudo apt update
          sudo apt install python-tk





          share|improve this answer



















          • 1




            Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
            – Sergiy Kolodyazhnyy
            Dec 8 at 18:30


















          up vote
          4
          down vote














          For example $20 trillion dollars / 50 million taxpayers would be entered as:



          20t / 50m




          I will do a frame challenge



          The answer here isn't to find software that supports this format, but to learn a standard format used in both calculators, programming languages and math: scientific notation.



          You write a number as a base (significand) and an exponent, e.g. 2*10⁵ for 20000. 20 trillions is thus 2*10¹³ - or 20*10¹². This will work on nearly all calculators, allows for compact and exact numbers, independently of language. Billion may for instance mean both 10⁹ and 10¹², depending on culture.



          In addition, this allows you to clearly define significant figures, as you may write 7.0*10³ or 7.02*10³, to note the number of known decimals.



          In computers this may additionally be written as ney for n*10^y, for instance 5e6 is interpreted as 5*10⁶. This form can be used in for instance octave.






          share|improve this answer























          • But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
            – terdon
            Dec 9 at 2:44






          • 1




            @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
            – dessert
            Dec 9 at 8:50










          • Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
            – terdon
            Dec 9 at 12:30






          • 1




            @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
            – vidarlo
            Dec 9 at 12:32










          • @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
            – WinEunuuchs2Unix
            2 days ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1098530%2fbig-number-calculator-human-readable-format%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          An initial solution only took a few minutes by taking this readily available Python Calculator GUI.





          Add a little code



          The full script is below but to summarize insert these lines near the top:



          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')


          Insert these lines near the bottom:



            Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)


          Insert these lines in the middle:



           def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]


          There are a few other cosmetic changes for larger font on HDPI monitor (1920x1080 pixels)



          Sample Calculator Window



          calc.py.png




          • This is a pretty standard calculator layout.

          • Notice the bottom row of keys we added.

          • You can click the keys or simply type in T instead of clicking T button.

          • Also notice how we entered 20 t / 50 M to represent 20 Trillion divided by 50 Million.

          • The result will be displayed as 400 K


          Full Python Script



          #-*-coding: utf-8-*-
          # NAME: calc.py
          # CALL: python calc.py
          # DATE: December 8, 2018
          # DESC: Calculator in E-Exa, P-Peta, T-Tetra, G-Giga, M-Mega and K-Kilo
          # NOTE: Requires Tkinter GUI libraries: sudo apt install python-tk

          # Majority Credit to: https://www.techinfected.net/2016/02/make-gui-calculator-in-python-windows-linux.html
          from Tkinter import *
          import tkFont
          import math

          class calc:
          def getandreplace(self):
          """replace x with * and ÷ with /"""

          self.expression = self.e.get()
          self.newtext=self.expression.replace(self.newdiv,'/')
          self.newtext=self.newtext.replace('x','*')
          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')

          def equals(self):
          """when the equal button is pressed"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.e.delete(0,END)
          self.value= self.convert() # Give result in K, M, G, T, P or E
          self.e.insert(0,self.value)

          def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]

          def squareroot(self):
          """squareroot method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqrtval=math.sqrt(self.value)
          self.e.delete(0,END)
          self.e.insert(0,self.sqrtval)

          def square(self):
          """square method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqval=math.pow(self.value,2)
          self.e.delete(0,END)
          self.e.insert(0,self.sqval)

          def clearall(self):
          """when clear button is pressed,clears the text input area"""
          self.e.delete(0,END)

          def clear1(self):
          self.txt=self.e.get()[:-1]
          self.e.delete(0,END)
          self.e.insert(0,self.txt)

          def action(self,argi):
          """pressed button's value is inserted into the end of the text area"""
          self.e.insert(END,argi)

          def __init__(self,master):
          """Constructor method"""
          master.title('Calculator')
          master.geometry()
          font = "Calibri 13"
          self.e = Entry(master, font = "Calibri 13")
          # self.e = Entry(master)
          self.e.grid(row=0,column=0,columnspan=6,pady=3)
          self.e.focus_set() #Sets focus on the input text area

          self.div='÷'
          self.newdiv=self.div.decode('utf-8')

          #Generating Buttons
          # Button(master,text="=",width=10,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text="=",width=8,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text='AC',width=3,command=lambda:self.clearall()).grid(row=1, column=4)
          Button(master,text='C',width=3,command=lambda:self.clear1()).grid(row=1, column=5)
          Button(master,text="+",width=3,command=lambda:self.action('+')).grid(row=4, column=3)
          Button(master,text="x",width=3,command=lambda:self.action('x')).grid(row=2, column=3)
          Button(master,text="-",width=3,command=lambda:self.action('-')).grid(row=3, column=3)
          Button(master,text="÷",width=3,command=lambda:self.action(self.newdiv)).grid(row=1, column=3)
          Button(master,text="%",width=3,command=lambda:self.action('%')).grid(row=4, column=2)
          Button(master,text="7",width=3,command=lambda:self.action('7')).grid(row=1, column=0)
          Button(master,text="8",width=3,command=lambda:self.action(8)).grid(row=1, column=1)
          Button(master,text="9",width=3,command=lambda:self.action(9)).grid(row=1, column=2)
          Button(master,text="4",width=3,command=lambda:self.action(4)).grid(row=2, column=0)
          Button(master,text="5",width=3,command=lambda:self.action(5)).grid(row=2, column=1)
          Button(master,text="6",width=3,command=lambda:self.action(6)).grid(row=2, column=2)
          Button(master,text="1",width=3,command=lambda:self.action(1)).grid(row=3, column=0)
          Button(master,text="2",width=3,command=lambda:self.action(2)).grid(row=3, column=1)
          Button(master,text="3",width=3,command=lambda:self.action(3)).grid(row=3, column=2)
          Button(master,text="0",width=3,command=lambda:self.action(0)).grid(row=4, column=0)
          Button(master,text=".",width=3,command=lambda:self.action('.')).grid(row=4, column=1)
          Button(master,text="(",width=3,command=lambda:self.action('(')).grid(row=2, column=4)
          Button(master,text=")",width=3,command=lambda:self.action(')')).grid(row=2, column=5)
          Button(master,text="√",width=3,command=lambda:self.squareroot()).grid(row=3, column=4)
          Button(master,text="x²",width=3,command=lambda:self.square()).grid(row=3, column=5)
          Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)
          #Main
          root = Tk()
          # Larger font for HDPI screen
          default_font = tkFont.nametofont("TkDefaultFont")
          default_font.configure(size=11)
          obj=calc(root) #object instantiated
          root.mainloop()


          Many thanks to the author (on first link above) for contributing this code!



          Install Tkinter



          You need python-tk (Tkinter) installed to use Python GUI Calculator:



          sudo apt update
          sudo apt install python-tk





          share|improve this answer



















          • 1




            Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
            – Sergiy Kolodyazhnyy
            Dec 8 at 18:30















          up vote
          6
          down vote



          accepted










          An initial solution only took a few minutes by taking this readily available Python Calculator GUI.





          Add a little code



          The full script is below but to summarize insert these lines near the top:



          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')


          Insert these lines near the bottom:



            Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)


          Insert these lines in the middle:



           def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]


          There are a few other cosmetic changes for larger font on HDPI monitor (1920x1080 pixels)



          Sample Calculator Window



          calc.py.png




          • This is a pretty standard calculator layout.

          • Notice the bottom row of keys we added.

          • You can click the keys or simply type in T instead of clicking T button.

          • Also notice how we entered 20 t / 50 M to represent 20 Trillion divided by 50 Million.

          • The result will be displayed as 400 K


          Full Python Script



          #-*-coding: utf-8-*-
          # NAME: calc.py
          # CALL: python calc.py
          # DATE: December 8, 2018
          # DESC: Calculator in E-Exa, P-Peta, T-Tetra, G-Giga, M-Mega and K-Kilo
          # NOTE: Requires Tkinter GUI libraries: sudo apt install python-tk

          # Majority Credit to: https://www.techinfected.net/2016/02/make-gui-calculator-in-python-windows-linux.html
          from Tkinter import *
          import tkFont
          import math

          class calc:
          def getandreplace(self):
          """replace x with * and ÷ with /"""

          self.expression = self.e.get()
          self.newtext=self.expression.replace(self.newdiv,'/')
          self.newtext=self.newtext.replace('x','*')
          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')

          def equals(self):
          """when the equal button is pressed"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.e.delete(0,END)
          self.value= self.convert() # Give result in K, M, G, T, P or E
          self.e.insert(0,self.value)

          def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]

          def squareroot(self):
          """squareroot method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqrtval=math.sqrt(self.value)
          self.e.delete(0,END)
          self.e.insert(0,self.sqrtval)

          def square(self):
          """square method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqval=math.pow(self.value,2)
          self.e.delete(0,END)
          self.e.insert(0,self.sqval)

          def clearall(self):
          """when clear button is pressed,clears the text input area"""
          self.e.delete(0,END)

          def clear1(self):
          self.txt=self.e.get()[:-1]
          self.e.delete(0,END)
          self.e.insert(0,self.txt)

          def action(self,argi):
          """pressed button's value is inserted into the end of the text area"""
          self.e.insert(END,argi)

          def __init__(self,master):
          """Constructor method"""
          master.title('Calculator')
          master.geometry()
          font = "Calibri 13"
          self.e = Entry(master, font = "Calibri 13")
          # self.e = Entry(master)
          self.e.grid(row=0,column=0,columnspan=6,pady=3)
          self.e.focus_set() #Sets focus on the input text area

          self.div='÷'
          self.newdiv=self.div.decode('utf-8')

          #Generating Buttons
          # Button(master,text="=",width=10,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text="=",width=8,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text='AC',width=3,command=lambda:self.clearall()).grid(row=1, column=4)
          Button(master,text='C',width=3,command=lambda:self.clear1()).grid(row=1, column=5)
          Button(master,text="+",width=3,command=lambda:self.action('+')).grid(row=4, column=3)
          Button(master,text="x",width=3,command=lambda:self.action('x')).grid(row=2, column=3)
          Button(master,text="-",width=3,command=lambda:self.action('-')).grid(row=3, column=3)
          Button(master,text="÷",width=3,command=lambda:self.action(self.newdiv)).grid(row=1, column=3)
          Button(master,text="%",width=3,command=lambda:self.action('%')).grid(row=4, column=2)
          Button(master,text="7",width=3,command=lambda:self.action('7')).grid(row=1, column=0)
          Button(master,text="8",width=3,command=lambda:self.action(8)).grid(row=1, column=1)
          Button(master,text="9",width=3,command=lambda:self.action(9)).grid(row=1, column=2)
          Button(master,text="4",width=3,command=lambda:self.action(4)).grid(row=2, column=0)
          Button(master,text="5",width=3,command=lambda:self.action(5)).grid(row=2, column=1)
          Button(master,text="6",width=3,command=lambda:self.action(6)).grid(row=2, column=2)
          Button(master,text="1",width=3,command=lambda:self.action(1)).grid(row=3, column=0)
          Button(master,text="2",width=3,command=lambda:self.action(2)).grid(row=3, column=1)
          Button(master,text="3",width=3,command=lambda:self.action(3)).grid(row=3, column=2)
          Button(master,text="0",width=3,command=lambda:self.action(0)).grid(row=4, column=0)
          Button(master,text=".",width=3,command=lambda:self.action('.')).grid(row=4, column=1)
          Button(master,text="(",width=3,command=lambda:self.action('(')).grid(row=2, column=4)
          Button(master,text=")",width=3,command=lambda:self.action(')')).grid(row=2, column=5)
          Button(master,text="√",width=3,command=lambda:self.squareroot()).grid(row=3, column=4)
          Button(master,text="x²",width=3,command=lambda:self.square()).grid(row=3, column=5)
          Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)
          #Main
          root = Tk()
          # Larger font for HDPI screen
          default_font = tkFont.nametofont("TkDefaultFont")
          default_font.configure(size=11)
          obj=calc(root) #object instantiated
          root.mainloop()


          Many thanks to the author (on first link above) for contributing this code!



          Install Tkinter



          You need python-tk (Tkinter) installed to use Python GUI Calculator:



          sudo apt update
          sudo apt install python-tk





          share|improve this answer



















          • 1




            Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
            – Sergiy Kolodyazhnyy
            Dec 8 at 18:30













          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          An initial solution only took a few minutes by taking this readily available Python Calculator GUI.





          Add a little code



          The full script is below but to summarize insert these lines near the top:



          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')


          Insert these lines near the bottom:



            Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)


          Insert these lines in the middle:



           def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]


          There are a few other cosmetic changes for larger font on HDPI monitor (1920x1080 pixels)



          Sample Calculator Window



          calc.py.png




          • This is a pretty standard calculator layout.

          • Notice the bottom row of keys we added.

          • You can click the keys or simply type in T instead of clicking T button.

          • Also notice how we entered 20 t / 50 M to represent 20 Trillion divided by 50 Million.

          • The result will be displayed as 400 K


          Full Python Script



          #-*-coding: utf-8-*-
          # NAME: calc.py
          # CALL: python calc.py
          # DATE: December 8, 2018
          # DESC: Calculator in E-Exa, P-Peta, T-Tetra, G-Giga, M-Mega and K-Kilo
          # NOTE: Requires Tkinter GUI libraries: sudo apt install python-tk

          # Majority Credit to: https://www.techinfected.net/2016/02/make-gui-calculator-in-python-windows-linux.html
          from Tkinter import *
          import tkFont
          import math

          class calc:
          def getandreplace(self):
          """replace x with * and ÷ with /"""

          self.expression = self.e.get()
          self.newtext=self.expression.replace(self.newdiv,'/')
          self.newtext=self.newtext.replace('x','*')
          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')

          def equals(self):
          """when the equal button is pressed"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.e.delete(0,END)
          self.value= self.convert() # Give result in K, M, G, T, P or E
          self.e.insert(0,self.value)

          def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]

          def squareroot(self):
          """squareroot method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqrtval=math.sqrt(self.value)
          self.e.delete(0,END)
          self.e.insert(0,self.sqrtval)

          def square(self):
          """square method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqval=math.pow(self.value,2)
          self.e.delete(0,END)
          self.e.insert(0,self.sqval)

          def clearall(self):
          """when clear button is pressed,clears the text input area"""
          self.e.delete(0,END)

          def clear1(self):
          self.txt=self.e.get()[:-1]
          self.e.delete(0,END)
          self.e.insert(0,self.txt)

          def action(self,argi):
          """pressed button's value is inserted into the end of the text area"""
          self.e.insert(END,argi)

          def __init__(self,master):
          """Constructor method"""
          master.title('Calculator')
          master.geometry()
          font = "Calibri 13"
          self.e = Entry(master, font = "Calibri 13")
          # self.e = Entry(master)
          self.e.grid(row=0,column=0,columnspan=6,pady=3)
          self.e.focus_set() #Sets focus on the input text area

          self.div='÷'
          self.newdiv=self.div.decode('utf-8')

          #Generating Buttons
          # Button(master,text="=",width=10,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text="=",width=8,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text='AC',width=3,command=lambda:self.clearall()).grid(row=1, column=4)
          Button(master,text='C',width=3,command=lambda:self.clear1()).grid(row=1, column=5)
          Button(master,text="+",width=3,command=lambda:self.action('+')).grid(row=4, column=3)
          Button(master,text="x",width=3,command=lambda:self.action('x')).grid(row=2, column=3)
          Button(master,text="-",width=3,command=lambda:self.action('-')).grid(row=3, column=3)
          Button(master,text="÷",width=3,command=lambda:self.action(self.newdiv)).grid(row=1, column=3)
          Button(master,text="%",width=3,command=lambda:self.action('%')).grid(row=4, column=2)
          Button(master,text="7",width=3,command=lambda:self.action('7')).grid(row=1, column=0)
          Button(master,text="8",width=3,command=lambda:self.action(8)).grid(row=1, column=1)
          Button(master,text="9",width=3,command=lambda:self.action(9)).grid(row=1, column=2)
          Button(master,text="4",width=3,command=lambda:self.action(4)).grid(row=2, column=0)
          Button(master,text="5",width=3,command=lambda:self.action(5)).grid(row=2, column=1)
          Button(master,text="6",width=3,command=lambda:self.action(6)).grid(row=2, column=2)
          Button(master,text="1",width=3,command=lambda:self.action(1)).grid(row=3, column=0)
          Button(master,text="2",width=3,command=lambda:self.action(2)).grid(row=3, column=1)
          Button(master,text="3",width=3,command=lambda:self.action(3)).grid(row=3, column=2)
          Button(master,text="0",width=3,command=lambda:self.action(0)).grid(row=4, column=0)
          Button(master,text=".",width=3,command=lambda:self.action('.')).grid(row=4, column=1)
          Button(master,text="(",width=3,command=lambda:self.action('(')).grid(row=2, column=4)
          Button(master,text=")",width=3,command=lambda:self.action(')')).grid(row=2, column=5)
          Button(master,text="√",width=3,command=lambda:self.squareroot()).grid(row=3, column=4)
          Button(master,text="x²",width=3,command=lambda:self.square()).grid(row=3, column=5)
          Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)
          #Main
          root = Tk()
          # Larger font for HDPI screen
          default_font = tkFont.nametofont("TkDefaultFont")
          default_font.configure(size=11)
          obj=calc(root) #object instantiated
          root.mainloop()


          Many thanks to the author (on first link above) for contributing this code!



          Install Tkinter



          You need python-tk (Tkinter) installed to use Python GUI Calculator:



          sudo apt update
          sudo apt install python-tk





          share|improve this answer














          An initial solution only took a few minutes by taking this readily available Python Calculator GUI.





          Add a little code



          The full script is below but to summarize insert these lines near the top:



          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')


          Insert these lines near the bottom:



            Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)


          Insert these lines in the middle:



           def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]


          There are a few other cosmetic changes for larger font on HDPI monitor (1920x1080 pixels)



          Sample Calculator Window



          calc.py.png




          • This is a pretty standard calculator layout.

          • Notice the bottom row of keys we added.

          • You can click the keys or simply type in T instead of clicking T button.

          • Also notice how we entered 20 t / 50 M to represent 20 Trillion divided by 50 Million.

          • The result will be displayed as 400 K


          Full Python Script



          #-*-coding: utf-8-*-
          # NAME: calc.py
          # CALL: python calc.py
          # DATE: December 8, 2018
          # DESC: Calculator in E-Exa, P-Peta, T-Tetra, G-Giga, M-Mega and K-Kilo
          # NOTE: Requires Tkinter GUI libraries: sudo apt install python-tk

          # Majority Credit to: https://www.techinfected.net/2016/02/make-gui-calculator-in-python-windows-linux.html
          from Tkinter import *
          import tkFont
          import math

          class calc:
          def getandreplace(self):
          """replace x with * and ÷ with /"""

          self.expression = self.e.get()
          self.newtext=self.expression.replace(self.newdiv,'/')
          self.newtext=self.newtext.replace('x','*')
          self.newtext=self.newtext.replace(' ','')
          self.newtext=self.newtext.upper()
          self.newtext=self.newtext.replace('K','000')
          self.newtext=self.newtext.replace('M','000000')
          self.newtext=self.newtext.replace('G','000000000')
          self.newtext=self.newtext.replace('T','000000000000')
          self.newtext=self.newtext.replace('P','000000000000000')
          self.newtext=self.newtext.replace('E','000000000000000000')

          def equals(self):
          """when the equal button is pressed"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.e.delete(0,END)
          self.value= self.convert() # Give result in K, M, G, T, P or E
          self.e.insert(0,self.value)

          def convert(self):
          #2**10 = 1024
          power = 1000
          size=self.value
          n = 0
          Dic_powerN = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T', 5: 'P', 6: 'E'}
          while size > power:
          size /= power
          n += 1
          return size, Dic_powerN[n]

          def squareroot(self):
          """squareroot method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqrtval=math.sqrt(self.value)
          self.e.delete(0,END)
          self.e.insert(0,self.sqrtval)

          def square(self):
          """square method"""

          self.getandreplace()
          try:
          self.value= eval(self.newtext) #evaluate the expression using the eval function
          except SyntaxError or NameErrror:
          self.e.delete(0,END)
          self.e.insert(0,'Invalid Input!')
          else:
          self.sqval=math.pow(self.value,2)
          self.e.delete(0,END)
          self.e.insert(0,self.sqval)

          def clearall(self):
          """when clear button is pressed,clears the text input area"""
          self.e.delete(0,END)

          def clear1(self):
          self.txt=self.e.get()[:-1]
          self.e.delete(0,END)
          self.e.insert(0,self.txt)

          def action(self,argi):
          """pressed button's value is inserted into the end of the text area"""
          self.e.insert(END,argi)

          def __init__(self,master):
          """Constructor method"""
          master.title('Calculator')
          master.geometry()
          font = "Calibri 13"
          self.e = Entry(master, font = "Calibri 13")
          # self.e = Entry(master)
          self.e.grid(row=0,column=0,columnspan=6,pady=3)
          self.e.focus_set() #Sets focus on the input text area

          self.div='÷'
          self.newdiv=self.div.decode('utf-8')

          #Generating Buttons
          # Button(master,text="=",width=10,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text="=",width=8,command=lambda:self.equals()).grid(row=4, column=4,columnspan=2)
          Button(master,text='AC',width=3,command=lambda:self.clearall()).grid(row=1, column=4)
          Button(master,text='C',width=3,command=lambda:self.clear1()).grid(row=1, column=5)
          Button(master,text="+",width=3,command=lambda:self.action('+')).grid(row=4, column=3)
          Button(master,text="x",width=3,command=lambda:self.action('x')).grid(row=2, column=3)
          Button(master,text="-",width=3,command=lambda:self.action('-')).grid(row=3, column=3)
          Button(master,text="÷",width=3,command=lambda:self.action(self.newdiv)).grid(row=1, column=3)
          Button(master,text="%",width=3,command=lambda:self.action('%')).grid(row=4, column=2)
          Button(master,text="7",width=3,command=lambda:self.action('7')).grid(row=1, column=0)
          Button(master,text="8",width=3,command=lambda:self.action(8)).grid(row=1, column=1)
          Button(master,text="9",width=3,command=lambda:self.action(9)).grid(row=1, column=2)
          Button(master,text="4",width=3,command=lambda:self.action(4)).grid(row=2, column=0)
          Button(master,text="5",width=3,command=lambda:self.action(5)).grid(row=2, column=1)
          Button(master,text="6",width=3,command=lambda:self.action(6)).grid(row=2, column=2)
          Button(master,text="1",width=3,command=lambda:self.action(1)).grid(row=3, column=0)
          Button(master,text="2",width=3,command=lambda:self.action(2)).grid(row=3, column=1)
          Button(master,text="3",width=3,command=lambda:self.action(3)).grid(row=3, column=2)
          Button(master,text="0",width=3,command=lambda:self.action(0)).grid(row=4, column=0)
          Button(master,text=".",width=3,command=lambda:self.action('.')).grid(row=4, column=1)
          Button(master,text="(",width=3,command=lambda:self.action('(')).grid(row=2, column=4)
          Button(master,text=")",width=3,command=lambda:self.action(')')).grid(row=2, column=5)
          Button(master,text="√",width=3,command=lambda:self.squareroot()).grid(row=3, column=4)
          Button(master,text="x²",width=3,command=lambda:self.square()).grid(row=3, column=5)
          Button(master,text="E",width=3,command=lambda:self.action('E')).grid(row=5, column=0)
          Button(master,text="P",width=3,command=lambda:self.action('P')).grid(row=5, column=1)
          Button(master,text="T",width=3,command=lambda:self.action('T')).grid(row=5, column=2)
          Button(master,text="G",width=3,command=lambda:self.action('G')).grid(row=5, column=3)
          Button(master,text="M",width=3,command=lambda:self.action('M')).grid(row=5, column=4)
          Button(master,text="K",width=3,command=lambda:self.action('K')).grid(row=5, column=5)
          #Main
          root = Tk()
          # Larger font for HDPI screen
          default_font = tkFont.nametofont("TkDefaultFont")
          default_font.configure(size=11)
          obj=calc(root) #object instantiated
          root.mainloop()


          Many thanks to the author (on first link above) for contributing this code!



          Install Tkinter



          You need python-tk (Tkinter) installed to use Python GUI Calculator:



          sudo apt update
          sudo apt install python-tk






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 8 at 18:13

























          answered Dec 7 at 21:12









          WinEunuuchs2Unix

          41.5k1070158




          41.5k1070158








          • 1




            Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
            – Sergiy Kolodyazhnyy
            Dec 8 at 18:30














          • 1




            Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
            – Sergiy Kolodyazhnyy
            Dec 8 at 18:30








          1




          1




          Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
          – Sergiy Kolodyazhnyy
          Dec 8 at 18:30




          Tk is part of standard python library, so you should not need to install it unless your OS uses python minimal package. +1, looks very nice
          – Sergiy Kolodyazhnyy
          Dec 8 at 18:30












          up vote
          4
          down vote














          For example $20 trillion dollars / 50 million taxpayers would be entered as:



          20t / 50m




          I will do a frame challenge



          The answer here isn't to find software that supports this format, but to learn a standard format used in both calculators, programming languages and math: scientific notation.



          You write a number as a base (significand) and an exponent, e.g. 2*10⁵ for 20000. 20 trillions is thus 2*10¹³ - or 20*10¹². This will work on nearly all calculators, allows for compact and exact numbers, independently of language. Billion may for instance mean both 10⁹ and 10¹², depending on culture.



          In addition, this allows you to clearly define significant figures, as you may write 7.0*10³ or 7.02*10³, to note the number of known decimals.



          In computers this may additionally be written as ney for n*10^y, for instance 5e6 is interpreted as 5*10⁶. This form can be used in for instance octave.






          share|improve this answer























          • But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
            – terdon
            Dec 9 at 2:44






          • 1




            @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
            – dessert
            Dec 9 at 8:50










          • Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
            – terdon
            Dec 9 at 12:30






          • 1




            @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
            – vidarlo
            Dec 9 at 12:32










          • @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
            – WinEunuuchs2Unix
            2 days ago















          up vote
          4
          down vote














          For example $20 trillion dollars / 50 million taxpayers would be entered as:



          20t / 50m




          I will do a frame challenge



          The answer here isn't to find software that supports this format, but to learn a standard format used in both calculators, programming languages and math: scientific notation.



          You write a number as a base (significand) and an exponent, e.g. 2*10⁵ for 20000. 20 trillions is thus 2*10¹³ - or 20*10¹². This will work on nearly all calculators, allows for compact and exact numbers, independently of language. Billion may for instance mean both 10⁹ and 10¹², depending on culture.



          In addition, this allows you to clearly define significant figures, as you may write 7.0*10³ or 7.02*10³, to note the number of known decimals.



          In computers this may additionally be written as ney for n*10^y, for instance 5e6 is interpreted as 5*10⁶. This form can be used in for instance octave.






          share|improve this answer























          • But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
            – terdon
            Dec 9 at 2:44






          • 1




            @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
            – dessert
            Dec 9 at 8:50










          • Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
            – terdon
            Dec 9 at 12:30






          • 1




            @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
            – vidarlo
            Dec 9 at 12:32










          • @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
            – WinEunuuchs2Unix
            2 days ago













          up vote
          4
          down vote










          up vote
          4
          down vote










          For example $20 trillion dollars / 50 million taxpayers would be entered as:



          20t / 50m




          I will do a frame challenge



          The answer here isn't to find software that supports this format, but to learn a standard format used in both calculators, programming languages and math: scientific notation.



          You write a number as a base (significand) and an exponent, e.g. 2*10⁵ for 20000. 20 trillions is thus 2*10¹³ - or 20*10¹². This will work on nearly all calculators, allows for compact and exact numbers, independently of language. Billion may for instance mean both 10⁹ and 10¹², depending on culture.



          In addition, this allows you to clearly define significant figures, as you may write 7.0*10³ or 7.02*10³, to note the number of known decimals.



          In computers this may additionally be written as ney for n*10^y, for instance 5e6 is interpreted as 5*10⁶. This form can be used in for instance octave.






          share|improve this answer















          For example $20 trillion dollars / 50 million taxpayers would be entered as:



          20t / 50m




          I will do a frame challenge



          The answer here isn't to find software that supports this format, but to learn a standard format used in both calculators, programming languages and math: scientific notation.



          You write a number as a base (significand) and an exponent, e.g. 2*10⁵ for 20000. 20 trillions is thus 2*10¹³ - or 20*10¹². This will work on nearly all calculators, allows for compact and exact numbers, independently of language. Billion may for instance mean both 10⁹ and 10¹², depending on culture.



          In addition, this allows you to clearly define significant figures, as you may write 7.0*10³ or 7.02*10³, to note the number of known decimals.



          In computers this may additionally be written as ney for n*10^y, for instance 5e6 is interpreted as 5*10⁶. This form can be used in for instance octave.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 9 at 13:05









          Fabby

          26.2k1360159




          26.2k1360159










          answered Dec 7 at 21:34









          vidarlo

          8,81842342




          8,81842342












          • But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
            – terdon
            Dec 9 at 2:44






          • 1




            @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
            – dessert
            Dec 9 at 8:50










          • Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
            – terdon
            Dec 9 at 12:30






          • 1




            @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
            – vidarlo
            Dec 9 at 12:32










          • @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
            – WinEunuuchs2Unix
            2 days ago


















          • But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
            – terdon
            Dec 9 at 2:44






          • 1




            @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
            – dessert
            Dec 9 at 8:50










          • Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
            – terdon
            Dec 9 at 12:30






          • 1




            @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
            – vidarlo
            Dec 9 at 12:32










          • @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
            – WinEunuuchs2Unix
            2 days ago
















          But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
          – terdon
          Dec 9 at 2:44




          But this doesn't help the OP deal with MB vs MiB etc, as requested in the question. And don't try to tell me those can be expressed using 10 or 2 as a base respectively :). That's perfectly true but also perfectly irrelevant to this question. An answer suggesting someone learn a different notation instead of giving a solution with the notation requested isn't answering the question.
          – terdon
          Dec 9 at 2:44




          1




          1




          @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
          – dessert
          Dec 9 at 8:50




          @terdon That’s because one of the questions’ premises is wrong: That something like “20t” is unambiguous. It could mean “20 thousand”, “20 trillion”, “20 tons” (= 20 million), … Sometimes a question is best answered not as OP intended. Yes, I call this an XY problem.
          – dessert
          Dec 9 at 8:50












          Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
          – terdon
          Dec 9 at 12:30




          Sure, and "20t" could also mean "20 things" or "20 taps" but the OP defined it as "20 trillion". If that's your problem, ask the OP to clarify, but this is still answering a different question (which, had it been asked here would have been off topic anyway: we don't answer basic math questions here).
          – terdon
          Dec 9 at 12:30




          1




          1




          @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
          – vidarlo
          Dec 9 at 12:32




          @terdon It's an answer to OP's question, as it provides an explanation for why you do not need this. If a user asks how to do something, and there is better and more universal solutions, the user should be made aware of that.
          – vidarlo
          Dec 9 at 12:32












          @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
          – WinEunuuchs2Unix
          2 days ago




          @vidarlo FYI I just edited my question. Please let me know if any of the changes detracts from your answer.
          – WinEunuuchs2Unix
          2 days ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1098530%2fbig-number-calculator-human-readable-format%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

          Mangá

          Eduardo VII do Reino Unido