-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimple-GUI.py
36 lines (29 loc) · 950 Bytes
/
Simple-GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import tkinter as tk
def calculate_sum():
try:
A = float(entry_a.get())
B = float(entry_b.get())
result.set(f"Result: {A + B}")
except ValueError:
result.set("Invalid input!")
# Create a tkinter window
window = tk.Tk()
window.title("Simple Summation Calculator")
# Create labels and entry fields for A and B
label_a = tk.Label(window, text="A:")
label_b = tk.Label(window, text="B:")
entry_a = tk.Entry(window)
entry_b = tk.Entry(window)
label_a.grid(row=0, column=0)
label_b.grid(row=1, column=0)
entry_a.grid(row=0, column=1)
entry_b.grid(row=1, column=1)
# Create a button to calculate the sum
calculate_button = tk.Button(window, text="Calculate Sum", command=calculate_sum)
calculate_button.grid(row=2, columnspan=2)
# Display the result
result = tk.StringVar()
result_label = tk.Label(window, textvariable=result)
result_label.grid(row=3, columnspan=2)
# Start the GUI main loop
window.mainloop()