Advertisement
HariBG

Sumator

Dec 14th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. class Application(tk.Frame) :
  4.     def __init__(self, master=None):
  5.         super().__init__(master)
  6.  
  7.         self.pack()
  8.         self.create_widgets()
  9.  
  10.     def create_widgets(self):
  11.         #create widgets
  12.         self.firstNumberEntry = tk.Entry()
  13.         self.plusSign = tk.Label(text="+")
  14.         self.secondNumberEntry = tk.Entry()
  15.         self.equalSign = tk.Label(text="=")
  16.         self.resultLabel = tk.Label(text="Result...", bg="green", fg="white")
  17.         self.calculateButton = tk.Button(text="Calculate", command=self.calculate)
  18.  
  19.         # place widgets
  20.         self.firstNumberEntry.pack(side="left")
  21.         self.plusSign.pack(side="left")
  22.         self.secondNumberEntry.pack(side="left")
  23.         self.equalSign.pack(side="left")
  24.         self.resultLabel.pack(side="left")
  25.         self.calculateButton.pack(side="left")
  26.  
  27.     def calculate(self):
  28.             first_value = float(self.firstNumberEntry.get())
  29.             second_value = float(self.secondNumberEntry.get())
  30.             result = first_value + second_value
  31.             self.resultLabel.config(text=str(result), bg="green", fg="white")
  32.  
  33.  
  34.  
  35. # create the application
  36. app = Application()
  37. app.master.title("Sumator")
  38. app.master.minsize(width=100, height=50)
  39.  
  40. # start the program
  41. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement