Hello friends,
In this python tutorial for beginners video, we are going to create simple GUI calculator application using python tkinter module
Requirement; install tkinter module with command 'pip install tkinter'
Adding the code part used in video session, please comment your inputs and more topics
Code starts
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
canvas1 = tk.Canvas(root,width=300,height=300)
canvas1.pack()
def calc():
num1 = num1_entry.get()
num2 = num2_entry.get()
operator = opt_entry.get()
if operator == '+':
add = int(num1) + int(num2)
tk.messagebox.showinfo('Addition',add)
elif operator == '-':
sub = int(num1) - int(num2)
tk.messagebox.showinfo('Subtraction',sub)
print("The sub value is ", sub)
elif operator == '/':
div = int(num1) / int(num2)
tk.messagebox.showinfo('Division',div)
elif operator == '*':
mul = int(num1) * int(num2)
tk.messagebox.showinfo('Multiply',mul)
else:
tk.messagebox.showinfo('Alert','Wrong Operator')
root.destroy()
#header label
header_label = tk.Label(root,text="Welcome to Calculator")
canvas1.create_window(165,35,window=header_label)
#num1 input field
num1_entry = tk.Entry(root,text='Num1')
canvas1.create_window(215,75,window=num1_entry)
num1_label = tk.Label(root,text='Enter Num1 Value :')
canvas1.create_window(95,75,window=num1_label)
#num2 input field
num2_entry = tk.Entry(root,text='Num2')
canvas1.create_window(215,105,window=num2_entry)
num2_label = tk.Label(root,text='Enter Num2 Value :')
canvas1.create_window(95,105,window=num2_label)
#operator input field
opt_entry = tk.Entry(root,text='Opt')
canvas1.create_window(215,135,window=opt_entry)
opt_label = tk.Label(root,text='Select Operator :')
canvas1.create_window(95,135,window=opt_label)
#calc button
calc_button = tk.Button(root,text='Calculate',command=calc)
canvas1.create_window(215,165,window=calc_button)
root.mainloop()
Code Ends
python tutorial for beginners
python exercises
python learning
simply python application
tkinter python module
En esta página del sitio puede ver el video en línea Python Exercise #6 | Create GUI calculator application using Python Tkinter module | Technolazy de Duración hora minuto segunda en buena calidad , que subió el usuario Technolazy 27 julio 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 270 veces y le gustó 5 a los espectadores. Disfruta viendo!