Topic:Python GUI Program Area of Triangle with base and height
# 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:
- Python GUI Temperature Conversion Program Celsius to Fahrenhiet
- Python GUI Program Temperature Conversion Fahrenheit to Celsius
- Python Pounds to Kilogram Converter GUI tkinter Program
- Python 3 Four Function Calculator Program tkinter GUI
- Python Digital Clock Program using tkinter GUI
- Python Quotes Changer Program tkinter GUI
- Python 3 tkinter Spinbox GUI Program Example
- Python 3 tkinter Message Widget Program Examples
- Python 3 GUI Program tkinter Radio Buttons
- Adding Menus to Python 3 tkinter GUI Programs
- Python 3 GUI Program Add Two Numbers
- Python 3 GUI Miles to Kilometers Converter tkinter Program
- Python 3 tkinter GUI Kilogram to Pounds Program
- Python Set Label Text on Button Click tkinter GUI Program
- Show Label and Button Widgets Python Tkinter Program
- Python GUI Program Area of Triangle with base and height
- Python 3 Tkinter GUI Hello World Program
- Create and Show Root Window of tkinter GUI Program
Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com