Windows developers need to use tkinter library window
So the first thing is to come:
Import Tkinter AS t window = t.Tk () # create a window window.title ( ' mini-calculator ' ) # the name of the window is called 'mini-calculators' window.geometry ( ' 250x150 ' ) # The size of the window 250 * 150. Warning: symbol between the two numbers are not *, but lowercase x!
In this way we will complete the first thing to a "empty bucket" created, next to which is added a new element.
DEF hit_me (): # This function displays precautions when using the calculator L = t.Label (window, text = ' The calculator is a first generation, supports only four operations Math! ' , BG = ' Green ' , font = ( ' Music Videos Boli ' ,. 9 ), width = 35, height = 2 ) # define a label l.pack () # put into tab window to B = t.Button ( window, text = ' with before Use ' , width =. 6, height =. 1 , Command = hit_me) # define a button that calls "hit_me" function b.place (X = 0, Y = 0, = Anchor ' NW ' ) # the buttons on the window to
Such Before Using our calculator will do the work, followed by the addition computing.
DEF Calc (): # calculation function is deemed unnecessary to explain the A = int (e.get ()) # data input function will get out of the box B = e1.get () C = int (EE. GET ()) IF B == ' + ' : t.Label (window, text = ' = ' . STR + (A + C)) Place (X = 150, Y = 65, Anchor = ' NW ' ) elif B == ' - ' : t.Label (window, text = ' = ' + STR (AC)) Place (X = 150, Y = 65, Anchor =. ' NW ' ) elif B == ' * ': t.Label (window, text = ' = ' + STR (A * C)) Place (X = 150, Y = 65, Anchor =. ' NW ' ) the else : t.Label (window, text = ' = ' STR + (a / C)). Place (X = 150, Y = 65, Anchor = ' NW ' ) E = t.Entry (window, width = 10) # define an input box e.place (x = 10, 65 = Y, Anchor = ' NW ' ) # put it up screen E1 = t.Entry (window, width =. 1 ) e1.place (X = 85, Y = 65, Anchor = ' NW ' ) EE = T .Entry (window, width = 10 ) ee.place (X = 97, Y = 65, Anchor = ' NW ' ) t.Button (window, text = ' calculation ' , = Command Calc) .place (X = 125, Y = 90, Anchor = ' NW ' ) # run the calculation functions
Plus the version number
t.Label(window,text='version:1.0').place(x=100,y=125,anchor='nw')
Finally, let turn up window
window.mainloop ()
perfect!
Thus a full set of source code was written as codes
Import Tkinter AS t window = t.Tk () # create a window window.title ( ' mini-calculator ' ) # the name of the window is called 'mini-calculators' window.geometry ( ' 250x150 ' ) # The size of the window 250 * 150. Warning: the symbol * is not between the two figures, but lowercase X! DEF hit_me (): # This function displays precautions when using the calculator L = t.Label (window, text = ' The calculator for the first generation, supports only four operations Math! ' , BG = ' Green ' , font = ( ' Music Videos Boli ' ,. 9), Width = 35, height = 2 ) # define a label l.pack () # put into tab window to B = t.Button ( window, text = ' Before Use ' , width =. 6, height = . 1 , Command = hit_me) # define a button that calls "hit_me" function b.place (X = 0, Y = 0, = Anchor ' NW ' ) # the buttons on the window to DEF Calc (): # function calculation is deemed unnecessary to explain the a = int (e.get ()) # GET function to input data out of the box B = e1.get () C =int(ee.get()) if b=='+':t.Label(window,text='= '+str(a+c)).place(x=150,y=65,anchor='nw') elif b=='-':t.Label(window,text='= '+str(a-c)).place(x=150,y=65,anchor='nw') elif b=='*':t.Label(window,text='= '+str(a*c)).place(x=150,y=65,anchor='nw') else: t.Label (window, text = ' = ' . STR + (A / C)) Place (X = 150, Y = 65, Anchor = ' NW ' ) E = t.Entry (window, width = 10) # define an input box e.place (X = 10, Y = 65, Anchor = ' NW ' ) # put it up screen E1 = t.Entry (window, width =. 1 ) e1.place (X = 85, Y 65 =, = Anchor ' NW ' ) EE = t.Entry (window, width = 10 ) ee.place (X = 97, Y = 65, Anchor = ' NW ' ) t.Button (window, text = ' calculation ', Calc = Command) .place (X = 125, Y = 90, Anchor = ' NW ' ) # Run calculation function t.Label (window, text = ' Version: 1.0 ' ) .place (X = 100, Y = 125 , Anchor = ' NW ' ) window.mainloop ()
Let's turn him into a .exe, divided into the following steps:
1. Enter cmd: pip install pyinstaller, pyinstaller plug installation.
2. cmd adjusted to your * .py folder, then enter pyintaller -F -w * .py Note: * file name
As a result of your calculator appeared in the dist folder. (Supplementary Fig practical effect)
Just learning, some shallow, please forgive me