0% found this document useful (0 votes)
12 views4 pages

Shape Drawing Application

This helps students to find shape and size application

Uploaded by

gouhermaira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Shape Drawing Application

This helps students to find shape and size application

Uploaded by

gouhermaira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Shape Drawing Application

Introduction
The Shape Drawing Application is a simple yet versatile program designed to introduce users
to the basics of graphical interaction using Python's tkinter library. It provides an intuitive
interface where users can draw basic geometric shapes—such as squares, rectangles, ovals,
and triangles—on a canvas. The application is particularly useful for beginners learning
graphical programming and offers a hands-on experience in interacting with user interface
elements.

Graphical programming is a critical aspect of modern application development, as it


facilitates dynamic interaction between users and software. This application serves as an
educational tool, demonstrating how shapes can be rendered on a canvas with minimal code.
The ability to draw shapes by simply clicking buttons makes it highly user-friendly and
engaging.

Key features of the application include a canvas for visualization, buttons for selecting
shapes, and a clear option to reset the canvas. The program also demonstrates modular coding
practices, with dedicated functions for each shape and seamless integration of user input.
While simple, it forms the foundation for building more complex drawing tools, such as
applications with color selection, resizing, or shape rotation.

Algorithm
Steps:

1. Initialize the Application: Create the main window and a canvas widget for drawing.
2. Button Setup: Add buttons to the interface for selecting shapes (Square, Rectangle, Oval,
Triangle) and for clearing the canvas.
3. Shape Drawing:
o Each shape button is associated with a specific function.
o The function calculates the coordinates and draws the shape on the canvas using the
appropriate tkinter drawing method.
4. Clear Function:
o The "Clear" button removes all shapes from the canvas.
5. Run the Application: Start the application’s event loop.
Source Code
import tkinter as tk

class ShapeDrawerApp:

def __init__(self):

self.window = tk.Tk()

self.window.title("Shape Drawing Application")

self.canvas = tk.Canvas(self.window, width=500, height=500, bg="white")

self.canvas.grid(row=0, column=0, columnspan=4)

tk.Button(self.window, text="Square", command=self.draw_square, width=10).grid(row=1, column=0)

tk.Button(self.window, text="Rectangle", command=self.draw_rectangle, width=10).grid(row=1, column=1)

tk.Button(self.window, text="Oval", command=self.draw_oval, width=10).grid(row=1, column=2)

tk.Button(self.window, text="Triangle", command=self.draw_triangle, width=10).grid(row=1, column=3)

tk.Button(self.window, text="Clear", command=self.clear_canvas, width=10).grid(row=2, column=0, columnspan=4, pady=10)

def draw_square(self):

self.canvas.create_rectangle(100, 100, 200, 200, fill="blue", outline="black")

def draw_rectangle(self):

self.canvas.create_rectangle(50, 150, 250, 250, fill="green", outline="black")

def draw_oval(self):

self.canvas.create_oval(100, 100, 200, 300, fill="red", outline="black")

def draw_triangle(self):

points = [150, 50, 100, 200, 200, 200]

self.canvas.create_polygon(points, fill="yellow", outline="black")

def clear_canvas(self):

self.canvas.delete("all")

def run(self):

self.window.mainloop()

if __name__ == "__main__":

ShapeDrawerApp().run()
Outputs

Oval Shape Triangle Shape

Rectangle Shape Square Shape


Conclusion
This Shape Drawing Application provides:

1. Graphical Interaction: Intuitive buttons for selecting shapes.


2. Dynamic Visualization: Real-time drawing of shapes on the canvas.
3. Enhanced Functionality: Optional graph plotting for tracking user activity.

Applications:

 Educational tools for geometry visualization.


 Basic GUI practice with Python.
 Customizable drawing applications.

You might also like