Advertisement
TrashRat

Tkinter Calculator with Numpad support

Mar 6th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.98 KB | None | 0 0
  1. """
  2. Tkinter Calculator with full numpad support, hamfisted by your humble and gracious overlord, REED. 3/6/2018
  3. Each button press from the user is stored in a list and calculated only when the equals button has been hit. Due to some quirks the design,
  4. the percentage and square root operators can not be used at the same as normal operators handled by the eval() function. Exponents are also supported but not listed as a button in the GUI.
  5. GUI was created using PAGE version 4.9, in conjunction with Tcl version 8.6
  6.  
  7. TODO:
  8. Add PlusMinus, as the buttom right most button is useless as of this moment
  9. """
  10.  
  11. import sys
  12. import math
  13.  
  14. try:
  15.     from Tkinter import *
  16. except ImportError:
  17.     from tkinter import *
  18.  
  19. try:
  20.     import ttk
  21.     py3 = 0
  22. except ImportError:
  23.     import tkinter.ttk as ttk
  24.     py3 = 1
  25.  
  26. def vp_start_gui():
  27.     '''Starting point when module is the main routine.'''
  28.     global val, w, root
  29.     root = Tk()
  30.     top = Calcul8r (root)
  31.  
  32.     root.mainloop()
  33.  
  34. w = None
  35. def create_Calcul8r(root, *args, **kwargs):
  36.     '''Starting point when module is imported by another program.'''
  37.     global w, w_win, rt
  38.     rt = root
  39.     w = Toplevel (root)
  40.     top = Calcul8r (w)
  41.     return (w, top)
  42.  
  43. def destroy_Calcul8r():
  44.     global w
  45.     w.destroy()
  46.     w = None
  47.  
  48.  
  49. class Calcul8r:
  50.    
  51.     def __init__(self, top=None):
  52.  
  53.         FinEq = [] #stores button presses and the sum        
  54.         go = [] #stores a value that is checked by buttons 0-9 to see if the sum is displayed onscreen
  55.         calc = [] #checks if an operator button has been pressed
  56.        
  57.         def UpdateScreen(equation):
  58.             TooBig = False
  59.             value = equation
  60.            
  61.             if len(equation) == 20:
  62.                 del FinEq[:]
  63.                 TooBig = True
  64.                
  65.             if len(equation) > 1:
  66.                 value = "".join(equation) #turns the list of values into a string
  67.                
  68.             if not TooBig:
  69.                 self.EquationWindow.configure(text=value) #pushes new values to the screen
  70.             else:
  71.                 self.EquationWindow.configure(text="INTEGER OVERFLOW")
  72.            
  73.         self.EquationWindow = ttk.Label(top, anchor=E)
  74.         self.EquationWindow.place(relx=0.03, rely=0.04, height=109, width=298)
  75.         self.EquationWindow.configure(background="#c9c9c9")
  76.         self.EquationWindow.configure(foreground="#000000")
  77.         self.EquationWindow.configure(font=("Terminal",20))
  78.         self.EquationWindow.configure(relief=GROOVE)
  79.         self.EquationWindow.configure(anchor=CENTER)
  80.         self.EquationWindow.configure(justify=CENTER)
  81.         self.EquationWindow.configure(width=298)
  82.         self.EquationWindow.configure(text="", anchor=E)
  83.  
  84.         def Equals(event=None): #This equals function is horribly messy, but it works as intended.
  85.             TheSum = FinEq
  86.             TheSum = "".join(FinEq) #eval() only accepts strings, so we convert the list to a string before passing it through
  87.  
  88.             try: #percentage and square root aren't supported by eval(), so if the user enters that and it fails, it passes it to the nonstandard functions below
  89.                 FinalSum = eval(TheSum)
  90.                
  91.                 if FinalSum == 80085 or FinalSum == 8008135: #easter egg
  92.                     FinalSum = ["BOOBS! (.Y.)"]
  93.                     go.append("GO")
  94.                     UpdateScreen(FinalSum)
  95.                
  96.                 del FinEq[:]
  97.                 UpdateScreen(str(FinalSum))
  98.                 FinEq.append(str(FinalSum))
  99.                 go.append("GO")
  100.                
  101.             except(ValueError, IOError, SyntaxError, NameError) as err: #this code is a mess, but hey! it works
  102.  
  103.                 try:
  104.                     passed = False #for seeing if the if statements below have ran
  105.                    
  106.                     if FinEq[0] == "√":
  107.                         val = ''.join(FinEq)
  108.                         nval = val.split("√")
  109.                         Final_SQRT = math.sqrt(int(nval[1]))
  110.                         del FinEq[:]
  111.                         FinEq.append(str(Final_SQRT))
  112.                         UpdateScreen(str(Final_SQRT))
  113.                         go.append("GO")
  114.                         passed = True
  115.  
  116.                        
  117.                     val = ''.join(FinEq)    
  118.                     firstnum, operator,secondnum = val.partition("p%") #partions the value up into three different variables with the partion string in the middle. i.e., operator = p%
  119.        
  120.                     if operator == "p%": #checks to see if the operator symbol is present in the variable expected
  121.                         val = ''.join(FinEq)
  122.                         nval = val.split("p%")
  123.                         Final_Percent = float(nval[0]) / 100 * float(nval[1])
  124.                         del FinEq[:]
  125.                         FinEq.append(str(Final_Percent))
  126.                         UpdateScreen(str(Final_Percent))
  127.                         passed = True
  128.                         go.append("GO")
  129.                        
  130.                     if passed == False: #if no if statement has passed above, it's clearly not valid input
  131.                         del FinEq[:]
  132.                         FinalSum = ["INVALID_EQUATION"]
  133.                         UpdateScreen(FinalSum)
  134.                        
  135.                        
  136.                 except(ValueError, IOError, SyntaxError, NameError) as err:
  137.                     del FinEq[:]
  138.                     FinalSum = ["INVALID_EQUATION"]
  139.                     UpdateScreen(FinalSum)
  140.                
  141.            
  142.  
  143.         def Button0(event=None):
  144.             if "GO" in go:
  145.                 del go[:]
  146.                 del FinEq[:]
  147.             if "CA" in calc:
  148.                 del go[:]
  149.                 del calc[:]
  150.             FinEq.append("0")
  151.             UpdateScreen(FinEq)
  152.        
  153.         def Button1(event=None):
  154.             if "GO" in go:
  155.                 del go[:]
  156.                 del FinEq[:]
  157.             if "CA" in calc:
  158.                 del go[:]
  159.                 del calc[:]                
  160.             FinEq.append("1")
  161.             UpdateScreen(FinEq)
  162.  
  163.         def Button2(event=None):
  164.             if "GO" in go:
  165.                 del go[:]
  166.                 del FinEq[:]
  167.             if "CA" in calc:
  168.                 del go[:]
  169.                 del calc[:]
  170.             FinEq.append("2")
  171.             UpdateScreen(FinEq)
  172.  
  173.         def Button3(event=None):
  174.             if "GO" in go:
  175.                 del go[:]
  176.                 del FinEq[:]
  177.             if "CA" in calc:
  178.                 del go[:]
  179.                 del calc[:]
  180.             FinEq.append("3")
  181.             UpdateScreen(FinEq)
  182.  
  183.         def Button4(event=None):
  184.             if "GO" in go:
  185.                 del go[:]
  186.                 del FinEq[:]
  187.             if "CA" in calc:
  188.                 del go[:]
  189.                 del calc[:]
  190.             FinEq.append("4")
  191.             UpdateScreen(FinEq)
  192.  
  193.         def Button5(event=None):
  194.             if "GO" in go:
  195.                 del go[:]
  196.                 del FinEq[:]
  197.             FinEq.append("5")
  198.             UpdateScreen(FinEq)
  199.  
  200.         def Button6(event=None):
  201.             if "GO" in go:
  202.                 del go[:]
  203.                 del FinEq[:]
  204.             if "CA" in calc:
  205.                 del go[:]
  206.                 del calc[:]
  207.             FinEq.append("6")
  208.             UpdateScreen(FinEq)
  209.  
  210.         def Button7(event=None):
  211.             if "GO" in go:
  212.                 del go[:]
  213.                 del FinEq[:]
  214.             if "CA" in calc:
  215.                 del go[:]
  216.                 del calc[:]
  217.             FinEq.append("7")
  218.             UpdateScreen(FinEq)
  219.  
  220.         def Button8(event=None):
  221.             if "GO" in go:
  222.                 del go[:]
  223.                 del FinEq[:]
  224.             if "CA" in calc:
  225.                 del go[:]
  226.                 del calc[:]
  227.             FinEq.append("8")
  228.             UpdateScreen(FinEq)
  229.  
  230.         def Button9(event=None):
  231.             if "GO" in go:
  232.                 del go[:]
  233.                 del FinEq[:]
  234.             if "CA" in calc:
  235.                 del go[:]
  236.                 del calc[:]
  237.             FinEq.append("9")
  238.             UpdateScreen(FinEq)
  239.  
  240.         def Decimal(event=None):
  241.             del go[:]
  242.             calc.append("CA")
  243.             FinEq.append(".")
  244.             UpdateScreen(FinEq)
  245.  
  246.         def Add(event=None):
  247.             del go[:]
  248.             calc.append("CA")
  249.             FinEq.append("+")
  250.             UpdateScreen(FinEq)
  251.  
  252.         def Subtract(event=None):
  253.             del go[:]
  254.             calc.append("CA")
  255.             FinEq.append("-")
  256.             UpdateScreen(FinEq)
  257.  
  258.         def Multiply(event=None):
  259.             del go[:]
  260.             calc.append("CA")
  261.             FinEq.append("*")
  262.             UpdateScreen(FinEq)
  263.  
  264.         def Divide(event=None):
  265.             del go[:]
  266.             calc.append("CA")
  267.             FinEq.append("/")
  268.             UpdateScreen(FinEq)
  269.  
  270.         def FloorDivide(event=None):
  271.             del go[:]
  272.             calc.append("CA")
  273.             FinEq.append("//")
  274.             UpdateScreen(FinEq)
  275.  
  276.         def Modulo(event=None):
  277.             del go[:]
  278.             calc.append("CA")
  279.             FinEq.append("%")
  280.             UpdateScreen(FinEq)
  281.  
  282.         def Percentage(event=None):
  283.             del go[:]
  284.             calc.append("CA")
  285.             FinEq.append("p%")
  286.             UpdateScreen(FinEq)
  287.  
  288.  
  289.         def SquareRoot(event=None):
  290.             del go[:]
  291.             calc.append("CA")
  292.             FinEq.append("√")
  293.             UpdateScreen(FinEq)
  294.    
  295.  
  296.         def PlusMinus(event=None):
  297.             del go[:]
  298.             calc.append("CA")
  299.             pass
  300.  
  301.         def ClearAll(event=None):
  302.             del FinEq[:]
  303.             UpdateScreen(FinEq)
  304.  
  305.         def Exponent(event=None):
  306.             del go[:]
  307.             calc.append("CA")
  308.             FinEq.append("^")
  309.             UpdateScreen(FinEq)
  310.            
  311.         def BackSpace(event=None):
  312.             try:
  313.                 del FinEq[-1]
  314.                 UpdateScreen(FinEq)
  315.             except(IndexError) as err: #excepts IndexError and passes it, as hitting multiple backspaces when there are no values present in FinEq[] will cause one
  316.                 pass
  317.  
  318.        
  319.         '''This class configures and populates the toplevel window.
  320.           top is the toplevel containing window.'''
  321.         _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
  322.         _fgcolor = '#000000'  # X11 color: 'black'
  323.         _compcolor = '#d9d9d9' # X11 color: 'gray85'
  324.         _ana1color = '#d9d9d9' # X11 color: 'gray85'
  325.         _ana2color = '#d9d9d9' # X11 color: 'gray85'
  326.         self.style = ttk.Style()
  327.         if sys.platform == "win32":
  328.             self.style.theme_use('winnative')
  329.         self.style.configure('.',background=_bgcolor)
  330.         self.style.configure('.',foreground=_fgcolor)
  331.         self.style.configure('.',font="TkDefaultFont")
  332.         self.style.map('.',background=
  333.             [('selected', _compcolor), ('active',_ana2color)])
  334.  
  335.         top.geometry("320x382+792+210")
  336.         top.title("Calcul8r")
  337.         top.configure(background="#d9d9d9")
  338.  
  339.         #Tkinter doesnt differentiate between numpad arrows and regular arrows,
  340.         #so there is a slight quirk. the arrowpad can enter 6,2,4,8
  341.         top.bind("<Insert>", Button0)
  342.         top.bind("0", Button0)
  343.         top.bind("<End>", Button1)
  344.         top.bind("1", Button1)
  345.         top.bind("<Down>", Button2)
  346.         top.bind("2", Button2)
  347.         top.bind("<Next>", Button3)
  348.         top.bind("3", Button3)
  349.         top.bind("<Left>", Button4)
  350.         top.bind("4", Button4)
  351.         top.bind("<Clear>", Button5)
  352.         top.bind("5", Button5)
  353.         top.bind("<Right>", Button6)
  354.         top.bind("6", Button6)
  355.         top.bind("<Home>", Button7)
  356.         top.bind("7", Button7)
  357.         top.bind("<Up>", Button8)
  358.         top.bind("8", Button8)
  359.         top.bind("<Prior>", Button9)
  360.         top.bind("9", Button9)
  361.         top.bind("<minus>", Subtract)
  362.         top.bind("<plus>", Add)
  363.         top.bind("<equal>", Add)
  364.         top.bind("<Return>", Equals)
  365.         top.bind("<Delete>", Decimal)
  366.         top.bind("<period>", Decimal)
  367.         top.bind("<asterisk>", Multiply)
  368.         top.bind("<slash>", Divide)
  369.         top.bind("<percent>", Percentage)
  370.         top.bind("<asciicircum>", Exponent)
  371.         top.bind("<Num_Lock>", BackSpace)
  372.         top.bind("<BackSpace>", BackSpace)
  373.        
  374.         self.Bu0 = Button(top, command= Button0)
  375.         self.Bu0.place(relx=0.25, rely=0.9, height=34, width=78)
  376.         self.Bu0.configure(activebackground="#d9d9d9")
  377.         self.Bu0.configure(activeforeground="#000000")
  378.         self.Bu0.configure(background="#d9d9d9")
  379.         self.Bu0.configure(disabledforeground="#a3a3a3")
  380.         self.Bu0.configure(font="Font10")
  381.         self.Bu0.configure(foreground="#000000")
  382.         self.Bu0.configure(highlightbackground="#d9d9d9")
  383.         self.Bu0.configure(highlightcolor="black")
  384.         self.Bu0.configure(pady="0")
  385.         self.Bu0.configure(text='''0''')
  386.  
  387.         self.Bu1 = Button(top, command = Button1)
  388.         self.Bu1.place(relx=0.0, rely=0.79, height=34, width=78)
  389.         self.Bu1.configure(activebackground="#d9d9d9")
  390.         self.Bu1.configure(activeforeground="#000000")
  391.         self.Bu1.configure(background="#d9d9d9")
  392.         self.Bu1.configure(disabledforeground="#a3a3a3")
  393.         self.Bu1.configure(font="Font10")
  394.         self.Bu1.configure(foreground="#000000")
  395.         self.Bu1.configure(highlightbackground="#d9d9d9")
  396.         self.Bu1.configure(highlightcolor="black")
  397.         self.Bu1.configure(pady="0")
  398.         self.Bu1.configure(text='''1''')
  399.  
  400.         self.Bu2 = Button(top, command = Button2)
  401.         self.Bu2.place(relx=0.25, rely=0.79, height=34, width=78)
  402.         self.Bu2.configure(activebackground="#d9d9d9")
  403.         self.Bu2.configure(activeforeground="#000000")
  404.         self.Bu2.configure(background="#d9d9d9")
  405.         self.Bu2.configure(disabledforeground="#a3a3a3")
  406.         self.Bu2.configure(font="Font10")
  407.         self.Bu2.configure(foreground="#000000")
  408.         self.Bu2.configure(highlightbackground="#d9d9d9")
  409.         self.Bu2.configure(highlightcolor="black")
  410.         self.Bu2.configure(pady="0")
  411.         self.Bu2.configure(text='''2''')
  412.  
  413.         self.Bu3 = Button(top, command = Button3)
  414.         self.Bu3.place(relx=0.5, rely=0.79, height=34, width=78)
  415.         self.Bu3.configure(activebackground="#d9d9d9")
  416.         self.Bu3.configure(activeforeground="#000000")
  417.         self.Bu3.configure(background="#d9d9d9")
  418.         self.Bu3.configure(disabledforeground="#a3a3a3")
  419.         self.Bu3.configure(font="Font10")
  420.         self.Bu3.configure(foreground="#000000")
  421.         self.Bu3.configure(highlightbackground="#d9d9d9")
  422.         self.Bu3.configure(highlightcolor="black")
  423.         self.Bu3.configure(pady="0")
  424.         self.Bu3.configure(text='''3''')
  425.  
  426.         self.Bu4 = Button(top, command = Button4)
  427.         self.Bu4.place(relx=0.0, rely=0.69, height=34, width=78)
  428.         self.Bu4.configure(activebackground="#d9d9d9")
  429.         self.Bu4.configure(activeforeground="#000000")
  430.         self.Bu4.configure(background="#d9d9d9")
  431.         self.Bu4.configure(disabledforeground="#a3a3a3")
  432.         self.Bu4.configure(font="Font10")
  433.         self.Bu4.configure(foreground="#000000")
  434.         self.Bu4.configure(highlightbackground="#d9d9d9")
  435.         self.Bu4.configure(highlightcolor="black")
  436.         self.Bu4.configure(pady="0")
  437.         self.Bu4.configure(text='''4''')
  438.  
  439.         self.Bu5 = Button(top, command = Button5)
  440.         self.Bu5.place(relx=0.25, rely=0.69, height=34, width=78)
  441.         self.Bu5.configure(activebackground="#d9d9d9")
  442.         self.Bu5.configure(activeforeground="#000000")
  443.         self.Bu5.configure(background="#d9d9d9")
  444.         self.Bu5.configure(disabledforeground="#a3a3a3")
  445.         self.Bu5.configure(font="Font10")
  446.         self.Bu5.configure(foreground="#000000")
  447.         self.Bu5.configure(highlightbackground="#d9d9d9")
  448.         self.Bu5.configure(highlightcolor="black")
  449.         self.Bu5.configure(pady="0")
  450.         self.Bu5.configure(text='''5''')
  451.  
  452.         self.Bu6 = Button(top, command = Button6)
  453.         self.Bu6.place(relx=0.5, rely=0.69, height=34, width=78)
  454.         self.Bu6.configure(activebackground="#d9d9d9")
  455.         self.Bu6.configure(activeforeground="#000000")
  456.         self.Bu6.configure(background="#d9d9d9")
  457.         self.Bu6.configure(disabledforeground="#a3a3a3")
  458.         self.Bu6.configure(font="Font10")
  459.         self.Bu6.configure(foreground="#000000")
  460.         self.Bu6.configure(highlightbackground="#d9d9d9")
  461.         self.Bu6.configure(highlightcolor="black")
  462.         self.Bu6.configure(pady="0")
  463.         self.Bu6.configure(text='''6''')
  464.  
  465.         self.Bu7 = Button(top, command = Button7)
  466.         self.Bu7.place(relx=0.0, rely=0.58, height=34, width=78)
  467.         self.Bu7.configure(activebackground="#d9d9d9")
  468.         self.Bu7.configure(activeforeground="#000000")
  469.         self.Bu7.configure(background="#d9d9d9")
  470.         self.Bu7.configure(disabledforeground="#a3a3a3")
  471.         self.Bu7.configure(font="Font10")
  472.         self.Bu7.configure(foreground="#000000")
  473.         self.Bu7.configure(highlightbackground="#d9d9d9")
  474.         self.Bu7.configure(highlightcolor="black")
  475.         self.Bu7.configure(pady="0")
  476.         self.Bu7.configure(text='''7''')
  477.  
  478.         self.Bu8 = Button(top, command = Button8)
  479.         self.Bu8.place(relx=0.25, rely=0.58, height=34, width=78)
  480.         self.Bu8.configure(activebackground="#d9d9d9")
  481.         self.Bu8.configure(activeforeground="#000000")
  482.         self.Bu8.configure(background="#d9d9d9")
  483.         self.Bu8.configure(disabledforeground="#a3a3a3")
  484.         self.Bu8.configure(font="Font10")
  485.         self.Bu8.configure(foreground="#000000")
  486.         self.Bu8.configure(highlightbackground="#d9d9d9")
  487.         self.Bu8.configure(highlightcolor="black")
  488.         self.Bu8.configure(pady="0")
  489.         self.Bu8.configure(text='''8''')
  490.  
  491.         self.Bu9 = Button(top, command = Button9)
  492.         self.Bu9.place(relx=0.5, rely=0.58, height=34, width=78)
  493.         self.Bu9.configure(activebackground="#d9d9d9")
  494.         self.Bu9.configure(activeforeground="#000000")
  495.         self.Bu9.configure(background="#d9d9d9")
  496.         self.Bu9.configure(disabledforeground="#a3a3a3")
  497.         self.Bu9.configure(font="Font10")
  498.         self.Bu9.configure(foreground="#000000")
  499.         self.Bu9.configure(highlightbackground="#d9d9d9")
  500.         self.Bu9.configure(highlightcolor="black")
  501.         self.Bu9.configure(pady="0")
  502.         self.Bu9.configure(text='''9''')
  503.  
  504.         self.CE = Button(top, command = ClearAll)
  505.         self.CE.place(relx=0.0, rely=0.48, height=34, width=78)
  506.         self.CE.configure(activebackground="#d9d9d9")
  507.         self.CE.configure(activeforeground="#000000")
  508.         self.CE.configure(background="#d9d9d9")
  509.         self.CE.configure(disabledforeground="#a3a3a3")
  510.         self.CE.configure(font="Font10")
  511.         self.CE.configure(foreground="#000000")
  512.         self.CE.configure(highlightbackground="#d9d9d9")
  513.         self.CE.configure(highlightcolor="black")
  514.         self.CE.configure(pady="0")
  515.         self.CE.configure(relief=GROOVE)
  516.         self.CE.configure(text='''CE''')
  517.  
  518.         self.ClearCurrent = Button(top, command = ClearAll)
  519.         self.ClearCurrent.place(relx=0.25, rely=0.48, height=34, width=78)
  520.         self.ClearCurrent.configure(activebackground="#d9d9d9")
  521.         self.ClearCurrent.configure(activeforeground="#000000")
  522.         self.ClearCurrent.configure(background="#d9d9d9")
  523.         self.ClearCurrent.configure(disabledforeground="#a3a3a3")
  524.         self.ClearCurrent.configure(font="Font10")
  525.         self.ClearCurrent.configure(foreground="#000000")
  526.         self.ClearCurrent.configure(highlightbackground="#d9d9d9")
  527.         self.ClearCurrent.configure(highlightcolor="black")
  528.         self.ClearCurrent.configure(pady="0")
  529.         self.ClearCurrent.configure(relief=GROOVE)
  530.         self.ClearCurrent.configure(text='''C''')
  531.  
  532.         self.BckSpc = Button(top, command = BackSpace)
  533.         self.BckSpc.place(relx=0.5, rely=0.48, height=34, width=78)
  534.         self.BckSpc.configure(activebackground="#d9d9d9")
  535.         self.BckSpc.configure(activeforeground="#000000")
  536.         self.BckSpc.configure(background="#d9d9d9")
  537.         self.BckSpc.configure(disabledforeground="#a3a3a3")
  538.         self.BckSpc.configure(font="Font10")
  539.         self.BckSpc.configure(foreground="#000000")
  540.         self.BckSpc.configure(highlightbackground="#d9d9d9")
  541.         self.BckSpc.configure(highlightcolor="black")
  542.         self.BckSpc.configure(pady="0")
  543.         self.BckSpc.configure(relief=GROOVE)
  544.         self.BckSpc.configure(text='''↩''')
  545.  
  546.         self.PlusMinus = Button(top)
  547.         self.PlusMinus.place(relx=0.0, rely=0.9, height=34, width=78)
  548.         self.PlusMinus.configure(activebackground="#d9d9d9")
  549.         self.PlusMinus.configure(activeforeground="#000000")
  550.         self.PlusMinus.configure(background="#d9d9d9")
  551.         self.PlusMinus.configure(disabledforeground="#a3a3a3")
  552.         self.PlusMinus.configure(font="Font10")
  553.         self.PlusMinus.configure(foreground="#000000")
  554.         self.PlusMinus.configure(highlightbackground="#d9d9d9")
  555.         self.PlusMinus.configure(highlightcolor="black")
  556.         self.PlusMinus.configure(pady="0")
  557.         self.PlusMinus.configure(relief=GROOVE)
  558.         self.PlusMinus.configure(text='''±''')
  559.  
  560.         self.Decimal = Button(top, command = Decimal)
  561.         self.Decimal.place(relx=0.5, rely=0.9, height=34, width=78)
  562.         self.Decimal.configure(activebackground="#d9d9d9")
  563.         self.Decimal.configure(activeforeground="#000000")
  564.         self.Decimal.configure(background="#d9d9d9")
  565.         self.Decimal.configure(disabledforeground="#a3a3a3")
  566.         self.Decimal.configure(font="Font10")
  567.         self.Decimal.configure(foreground="#000000")
  568.         self.Decimal.configure(highlightbackground="#d9d9d9")
  569.         self.Decimal.configure(highlightcolor="black")
  570.         self.Decimal.configure(pady="0")
  571.         self.Decimal.configure(relief=GROOVE)
  572.         self.Decimal.configure(text='''.''')
  573.  
  574.         self.Equals = Button(top, command = Equals)
  575.         self.Equals.place(relx=0.75, rely=0.9, height=34, width=78)
  576.         self.Equals.configure(activebackground="#d9d9d9")
  577.         self.Equals.configure(activeforeground="#000000")
  578.         self.Equals.configure(background="#d9d9d9")
  579.         self.Equals.configure(disabledforeground="#a3a3a3")
  580.         self.Equals.configure(font="Font10")
  581.         self.Equals.configure(foreground="#000000")
  582.         self.Equals.configure(highlightbackground="#d9d9d9")
  583.         self.Equals.configure(highlightcolor="black")
  584.         self.Equals.configure(pady="0")
  585.         self.Equals.configure(relief=GROOVE)
  586.         self.Equals.configure(text='''=''')
  587.  
  588.         self.Add = Button(top, command = Add)
  589.         self.Add.place(relx=0.75, rely=0.79, height=34, width=78)
  590.         self.Add.configure(activebackground="#d9d9d9")
  591.         self.Add.configure(activeforeground="#000000")
  592.         self.Add.configure(background="#d9d9d9")
  593.         self.Add.configure(disabledforeground="#a3a3a3")
  594.         self.Add.configure(font="Font10")
  595.         self.Add.configure(foreground="#000000")
  596.         self.Add.configure(highlightbackground="#d9d9d9")
  597.         self.Add.configure(highlightcolor="black")
  598.         self.Add.configure(pady="0")
  599.         self.Add.configure(relief=GROOVE)
  600.         self.Add.configure(text='''+''')
  601.  
  602.         self.Subtract = Button(top, command = Subtract)
  603.         self.Subtract.place(relx=0.75, rely=0.69, height=34, width=78)
  604.         self.Subtract.configure(activebackground="#d9d9d9")
  605.         self.Subtract.configure(activeforeground="#000000")
  606.         self.Subtract.configure(background="#d9d9d9")
  607.         self.Subtract.configure(disabledforeground="#a3a3a3")
  608.         self.Subtract.configure(font="Font10")
  609.         self.Subtract.configure(foreground="#000000")
  610.         self.Subtract.configure(highlightbackground="#d9d9d9")
  611.         self.Subtract.configure(highlightcolor="black")
  612.         self.Subtract.configure(pady="0")
  613.         self.Subtract.configure(relief=GROOVE)
  614.         self.Subtract.configure(text='''-''')
  615.  
  616.         self.Multiply = Button(top, command = Multiply)
  617.         self.Multiply.place(relx=0.75, rely=0.58, height=34, width=78)
  618.         self.Multiply.configure(activebackground="#d9d9d9")
  619.         self.Multiply.configure(activeforeground="#000000")
  620.         self.Multiply.configure(background="#d9d9d9")
  621.         self.Multiply.configure(disabledforeground="#a3a3a3")
  622.         self.Multiply.configure(font="Font10")
  623.         self.Multiply.configure(foreground="#000000")
  624.         self.Multiply.configure(highlightbackground="#d9d9d9")
  625.         self.Multiply.configure(highlightcolor="black")
  626.         self.Multiply.configure(pady="0")
  627.         self.Multiply.configure(relief=GROOVE)
  628.         self.Multiply.configure(text='''x''')
  629.  
  630.         self.Divide = Button(top, command = Divide )
  631.         self.Divide.place(relx=0.75, rely=0.48, height=34, width=78)
  632.         self.Divide.configure(activebackground="#d9d9d9")
  633.         self.Divide.configure(activeforeground="#000000")
  634.         self.Divide.configure(background="#d9d9d9")
  635.         self.Divide.configure(disabledforeground="#a3a3a3")
  636.         self.Divide.configure(font="Font10")
  637.         self.Divide.configure(foreground="#000000")
  638.         self.Divide.configure(highlightbackground="#d9d9d9")
  639.         self.Divide.configure(highlightcolor="black")
  640.         self.Divide.configure(pady="0")
  641.         self.Divide.configure(relief=GROOVE)
  642.         self.Divide.configure(text='''÷''')
  643.  
  644.         self.Percentage = Button(top, command = Percentage)
  645.         self.Percentage.place(relx=0.0, rely=0.37, height=34, width=78)
  646.         self.Percentage.configure(activebackground="#d9d9d9")
  647.         self.Percentage.configure(activeforeground="#000000")
  648.         self.Percentage.configure(background="#d9d9d9")
  649.         self.Percentage.configure(disabledforeground="#a3a3a3")
  650.         self.Percentage.configure(font="Font10")
  651.         self.Percentage.configure(foreground="#000000")
  652.         self.Percentage.configure(highlightbackground="#d9d9d9")
  653.         self.Percentage.configure(highlightcolor="black")
  654.         self.Percentage.configure(pady="0")
  655.         self.Percentage.configure(relief=GROOVE)
  656.         self.Percentage.configure(text='''%''')
  657.  
  658.         self.SquareRoot = Button(top, command = SquareRoot)
  659.         self.SquareRoot.place(relx=0.25, rely=0.37, height=34, width=78)
  660.         self.SquareRoot.configure(activebackground="#d9d9d9")
  661.         self.SquareRoot.configure(activeforeground="#000000")
  662.         self.SquareRoot.configure(background="#d9d9d9")
  663.         self.SquareRoot.configure(disabledforeground="#a3a3a3")
  664.         self.SquareRoot.configure(font="Font10")
  665.         self.SquareRoot.configure(foreground="#000000")
  666.         self.SquareRoot.configure(highlightbackground="#d9d9d9")
  667.         self.SquareRoot.configure(highlightcolor="black")
  668.         self.SquareRoot.configure(pady="0")
  669.         self.SquareRoot.configure(relief=GROOVE)
  670.         self.SquareRoot.configure(text='''√''')
  671.  
  672.         self.Modulo = Button(top, command = Modulo)
  673.         self.Modulo.place(relx=0.5, rely=0.37, height=34, width=78)
  674.         self.Modulo.configure(activebackground="#d9d9d9")
  675.         self.Modulo.configure(activeforeground="#000000")
  676.         self.Modulo.configure(background="#d9d9d9")
  677.         self.Modulo.configure(disabledforeground="#a3a3a3")
  678.         self.Modulo.configure(font="Font10")
  679.         self.Modulo.configure(foreground="#000000")
  680.         self.Modulo.configure(highlightbackground="#d9d9d9")
  681.         self.Modulo.configure(highlightcolor="black")
  682.         self.Modulo.configure(pady="0")
  683.         self.Modulo.configure(relief=GROOVE)
  684.         self.Modulo.configure(text='''mod''')
  685.  
  686.         self.FloorDivide = Button(top, command = FloorDivide)
  687.         self.FloorDivide.place(relx=0.75, rely=0.37, height=34, width=78)
  688.         self.FloorDivide.configure(activebackground="#d9d9d9")
  689.         self.FloorDivide.configure(activeforeground="#000000")
  690.         self.FloorDivide.configure(background="#d9d9d9")
  691.         self.FloorDivide.configure(disabledforeground="#a3a3a3")
  692.         self.FloorDivide.configure(font="Font10")
  693.         self.FloorDivide.configure(foreground="#000000")
  694.         self.FloorDivide.configure(highlightbackground="#d9d9d9")
  695.         self.FloorDivide.configure(highlightcolor="black")
  696.         self.FloorDivide.configure(pady="0")
  697.         self.FloorDivide.configure(relief=GROOVE)
  698.         self.FloorDivide.configure(text='''f÷''')
  699.  
  700.  
  701.     @staticmethod
  702.     def popup1(event):
  703.         Popupmenu1 = Menu(root, tearoff=0)
  704.         Popupmenu1.configure(activebackground="#f9f9f9")
  705.         Popupmenu1.configure(activeborderwidth="1")
  706.         Popupmenu1.configure(activeforeground="black")
  707.         Popupmenu1.configure(background="#d9d9d9")
  708.         Popupmenu1.configure(borderwidth="1")
  709.         Popupmenu1.configure(disabledforeground="#a3a3a3")
  710.         Popupmenu1.configure(font="{Segoe UI} 9")
  711.         Popupmenu1.configure(foreground="black")
  712.         Popupmenu1.post(event.x_root, event.y_root)
  713.  
  714.  
  715.  
  716. if __name__ == '__main__':
  717.     vp_start_gui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement