Python GUI Area of Triangle

By | March 30, 2020

Topic:Python GUI Program Area of Triangle with base and height

"<yoastmark

# Python GUI Program to calculate 
# Area of a Triangle
# When base and height given
# www.EasyCodebook.com

from tkinter import *


def calculate_area():
	base = float(entry1.get())
	height = float(entry2.get())
	area = 1 / 2 * base * height 
	output_label.configure(text = ' Area of Triangle= {:.2f} ' .format(area))
	
main_window = Tk()
main_window.title('Python GUI TUTORIALS, www.EasyCodeBook.com ')

message_label1 = Label(text= 'Enter base: ' ,font=( ' Verdana ' , 18))
message_label2 = Label(text= ' Enter height: ' ,font=( ' Verdana ' , 18))
output_label = Label(font=( ' Verdana ' , 18), text='Area of Triangle is:')
entry1 = Entry(font=( ' Verdana ' , 18), width=6)
entry2 = Entry(font=( ' Verdana ' , 18), width=6)
calc_button = Button(text= ' Calculate Area ' , font=( ' Verdana ' , 16),command=calculate_area)

message_label1.grid(row=1, column=0)
entry1.grid(row=1, column=1)

message_label2.grid(row=2, column=0)
entry2.grid(row=2, column=1)

calc_button.grid(row=1, column=2, rowspan=2)
output_label.grid(row=3, column=0, columnspan=3)
mainloop()

How this program works?

  • We use Python tkinter module to create GUI of this application
  • First of all we create a main window for the program.
  • we set the title of the main window.
  • create a label widget with message “Enter base“.
  • create a label widget with message “Enter height:“.
  • create a two text boxes / entry widgets to get the user input
  • create a button and attached a function calculate_area() using command=calculate_area
  • Hence when the user will input base and height  in the entry widgets and click on the button, the calculate_area() function will execute.
  • This calculate_area() function will calculate and show the area of the triangle in a label.

Perfect Programming Tutorials, Python , Java, C Language, C++

 

You would also like Python GUI Programs using tkinter Module:

  1. Python GUI Temperature Conversion Program Celsius to Fahrenhiet
  2. Python GUI Program Temperature Conversion Fahrenheit to Celsius
  3. Python Pounds to Kilogram Converter GUI tkinter Program
  4. Python 3 Four Function Calculator Program tkinter GUI
  5. Python Digital Clock Program using tkinter GUI
  6. Python Quotes Changer Program tkinter GUI
  7. Python 3 tkinter Spinbox GUI Program Example
  8. Python 3 tkinter Message Widget Program Examples
  9. Python 3 GUI Program tkinter Radio Buttons
  10. Adding Menus to Python 3 tkinter GUI Programs
  11. Python 3 GUI Program Add Two Numbers
  12. Python 3 GUI Miles to Kilometers Converter tkinter Program
  13. Python 3 tkinter GUI Kilogram to Pounds Program
  14. Python Set Label Text on Button Click tkinter GUI Program
  15. Show Label and Button Widgets Python Tkinter Program
  16. Python GUI Program Area of Triangle with base and height
  17. Python 3 Tkinter GUI Hello World Program
  18. Create and Show Root Window of tkinter GUI Program

 

One thought on “Python GUI Area of Triangle

  1. Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *