Advertisement
c0d3dsk1lls

Calculator by C0D3D @ codedskills.net

Jun 10th, 2022 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.21 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. # IF YOU ENJOYED THIS CALCULATOR, PLEASE SUPPORT OUR COMMUNITY BY REGISTERING @
  6. # MY WEBSITE           https://codedskills.net or https://codedskills.org
  7. #---------------------------------------------------------------------------------
  8. # OUR DISCORD          https://discord.gg/vTtUcNa7Ya
  9.  
  10. # MY FACEBOOK PAGE     https://www.facebook.com/CodedSkillsAdmin
  11.  
  12. # OUR FACEBOOK GROUP   https://www.facebook.com/groups/1960554790806573
  13.  
  14. # YOU MAY ALSO REACH ME AT          ( [email protected] )
  15. #-------------------------------------------------------------------------
  16.  
  17.  
  18.  
  19.  
  20. from tkinter import*
  21. import webbrowser
  22. #-----------------------------------------------------
  23.  
  24. new = 1                                                          
  25. url = "http://192.168.0.28/myserver/phpBB3/"                        
  26. root = Tk()                                                          
  27. root.title("   Calculator")  
  28. root.configure(background='black')                                    
  29. e = Entry(root, fg="red", bg="black", width=30, borderwidth=10)      
  30. e.grid(row=0, column=0, columnspan=3, padx=10, pady=10)            
  31. def b_click(number, fg="red", bg="black"):
  32.     current = e.get()
  33.     e.delete(0, END)                      
  34.     e.insert(0, str(current) + str(number))          
  35. #-----------------------------------------------------
  36. def b_clear():        
  37.     e.delete(0, END)              
  38. #-----------------------------------------------------
  39. def b_add():                
  40.     first_number = e.get()        
  41.     global f_num              
  42.     global math                      
  43.     math = "addition"        
  44.     f_num = int(first_number)    
  45.     e.delete(0, END)              
  46. #-----------------------------------------------------
  47. def b_left():
  48.     e.delete(0, END)    
  49. #-----------------------------------------------------
  50. def b_right():
  51.     e.delete(0, END)      
  52. #-----------------------------------------------------
  53. def b_equal():
  54.     second_number = e.get()
  55.     e.delete(0, END)    
  56.     if math == "addition":
  57.         e.insert(0, f_num + int(second_number))
  58.     if math == "subtraction":
  59.         e.insert(0, f_num - int(second_number))
  60.     if math == "multiplication":
  61.         e.insert(0, f_num * int(second_number))
  62.     if math == "division":
  63.         e.insert(0, f_num / int(second_number))
  64.     if math == "percentage":
  65.         e.insert(0, f_num % int(second_number))                
  66. #-----------------------------------------------------
  67. def b_subtract():
  68.     first_number = e.get()
  69.     global f_num
  70.     global math
  71.     math = "subtraction"
  72.     f_num = int(first_number)
  73.     e.delete(0, END)  
  74. #-----------------------------------------------------
  75. def b_percentage():
  76.     first_number = e.get()
  77.     global f_num
  78.     global math
  79.     math = "percentage"
  80.     f_num = int(first_number)
  81.     e.delete(0, END)        
  82. #-----------------------------------------------------
  83. def b_multiply():  
  84.     first_number = e.get()
  85.     global f_num
  86.     global math
  87.     math = "multiplication"
  88.     f_num = int(first_number)
  89.     e.delete(0, END)  
  90. #-----------------------------------------------------
  91. def b_division():
  92.     first_number = e.get()
  93.     global f_num
  94.     global math
  95.     math = "division"
  96.     f_num = int(first_number)
  97.     e.delete(0, END)      
  98. #-----------------------------------------------------
  99. def openweb():
  100.     webbrowser.open(url,new=new)    
  101.     global f_num    
  102. b_1 = Button(root, font = {'size' :50}, fg="red", bg="black", text="1", padx=43, pady=7, command=lambda: b_click(1))
  103. b_2 = Button(root, font = {'size' :50}, fg="red", bg="black", text="2", padx=46, pady=7, command=lambda: b_click(2))
  104. b_3 = Button(root, font = {'size' :50}, fg="red", bg="black", text="3", padx=43, pady=7, command=lambda: b_click(3))
  105. b_4 = Button(root, font = {'size' :50}, fg="red", bg="black", text="4", padx=43, pady=7, command=lambda: b_click(4))
  106. b_5 = Button(root, font = {'size' :50}, fg="red", bg="black", text="5", padx=46, pady=7, command=lambda: b_click(5))
  107. b_6 = Button(root, font = {'size' :50}, fg="red", bg="black", text="6", padx=43, pady=7, command=lambda: b_click(6))
  108. b_7 = Button(root, font = {'size' :50}, fg="red", bg="black", text="7", padx=43, pady=7, command=lambda: b_click(7))
  109. b_8 = Button(root, font = {'size' :50}, fg="red", bg="black", text="8", padx=46, pady=7, command=lambda: b_click(8))
  110. b_9 = Button(root, font = {'size' :50}, fg="red", bg="black", text="9", padx=43, pady=7, command=lambda: b_click(9))
  111. b_0 = Button(root, font = {'size' :50}, fg="lime", bg="black", text="0", padx=43, pady=6, command=lambda: b_click(0))
  112. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
  113. b_add = Button(root, fg="aqua", bg="black", text="Add⏆", padx=32, pady=9, command=b_add)
  114. b_equal = Button(root, fg="lime", bg="black", text="=", padx=96, pady=10, command=b_equal)
  115. b_clear = Button(root, fg="red", bg="black", text="Clear", padx=85, pady=7, command=b_clear)
  116. b_percentage = Button(root, fg="pink", bg="black", text="%", padx=45, pady=5, command=b_percentage)
  117. b_left = Button(root, fg="white", bg="black", text="MyWeb", padx=26, pady=5, command=openweb)
  118. b_right = Button(root, fg="red", bg="black", text="EXIT", padx=35, pady=5, command=root.quit)
  119. b_subtract = Button(root, fg="orange", bg="black", text="Minus-", padx=28, pady=9, command=b_subtract)
  120. b_multiply = Button(root, fg="purple", bg="black", text="Times ⤫", padx=23, pady=9, command=b_multiply)
  121. b_divide = Button(root, fg="yellow", bg="black", text="Divide÷", padx=23, pady=9, command=b_division)
  122. #++++1001000010101001+++++++++++++https://codedskills.net++++++++++++++++1001000010101001+++++++
  123.  
  124. #DEPENDING ON YOUR SCREEN RESOLUTION, YOU MAY NEED TO ADJUST THE BUTTON WIDTH
  125. #TO ADJUST THE BUTTON WIDTH, SIMPLY MODIFY THE "padx=?, pady=?" IN THE ABOVE CODE
  126.  
  127. b_1.grid(row=3, column=0)
  128. b_2.grid(row=3, column=1)
  129. b_3.grid(row=3, column=2)
  130. b_4.grid(row=2, column=0)
  131. b_5.grid(row=2, column=1)
  132. b_6.grid(row=2, column=2)
  133. b_7.grid(row=1, column=0)
  134. b_8.grid(row=1, column=1)
  135. b_9.grid(row=1, column=2)
  136. b_0.grid(row=4, column=0)
  137.  
  138. #-----------------------------------------------------
  139. b_clear.grid(row=4, column=1, columnspan=2)
  140. b_equal.grid(row=5, column=1, columnspan=2)
  141. b_add.grid(row=5, column=0)
  142. b_subtract.grid(row=6, column=0)
  143. b_multiply.grid(row=6, column=1)
  144. b_divide.grid(row=6, column=2)
  145. b_percentage.grid(row=10, column=1)
  146. b_left.grid(row=10, column=0)
  147. b_right.grid(row=10, column=2)
  148. #++++1001000010101001+++++++++++++https://codedskills.net++++++++++++++++1001000010101001+++++++
  149. root.mainloop()#----------------------------------------(END)    
  150. # IF YOU ENJOYED THIS CALCULATOR, PLEASE SUPPORT OUR COMMUNITY BY REGISTERING @
  151. # MY WEBSITE           https://codedskills.net or https://codedskills.org
  152. #---------------------------------------------------------------------------------
  153. # OUR DISCORD          https://discord.gg/vTtUcNa7Ya
  154.  
  155. # MY FACEBOOK PAGE     https://www.facebook.com/CodedSkillsAdmin
  156.  
  157. # OUR FACEBOOK GROUP   https://www.facebook.com/groups/1960554790806573
  158.  
  159. # YOU MAY ALSO REACH ME AT          ( [email protected] )
  160. #-------------------------------------------------------------------------
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement