- 1 year ago
Draw star using tkinter
Comment
1 / 1
Here's an example of how to draw a star using the tkinter library in Python:
pythonimport tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()
# Define the coordinates of the star points
star_points = [(200, 50), (235, 150), (350, 150), (255, 205), (295, 315),
(200, 250), (105, 315), (145, 205), (50, 150), (165, 150)]
# Draw the star
canvas.create_polygon(star_points, outline='black', fill='yellow', width=2)
root.mainloop()
This code creates a tkinter window with a canvas widget of width 400 and height 400. It then defines the coordinates of the points of the star as a list of tuples, and uses the create_polygon
method of the canvas widget to draw a polygon (the star) with those points, with an outline color of black, a fill color of yellow, and a line width of 2. Finally, the mainloop
method of the root window is called to start the event loop and display the star.