Video Discription |
Playlist: Creating GUI (Graphical User Interface) with Python and PyCharm and Visual Studio
https://www.youtube.com/playlist?list=PLedu-tgB8JaW2uR0M4UIbgT-mwAGy2XIT
from turtle import *
import time
win=Screen()
win.setup(width=720, height=450)
win.bgcolor("green")
drawing_area = Screen()
drawing_area.setup(width=750, height=500)
width(10)
def draw_top_rectangle(linecolor, length1=120, length2=150):
color(linecolor)
for i in range(2):
forward(length1)
left(90)
forward(length2)
left(90)
for i in range(2):
forward(-length1)
left(90)
forward(length2)
left(90)
begin_fill()
draw_top_rectangle('#FFFF99')
end_fill()
#draw_rectangle0draw_top_rectangle
# make a turtle object
t1 = Turtle()
t1.speed(1)
def drawSquare1():
t1.up()
t1.setpos(-80, -5)
t1.down()
t1.width(10)
t1.color('blue')
t1.forward(-40)
t1.left(90)
t1.forward(-80)
t1.left(90)
t1.forward(-40)
t1.left(90)
t1.forward(-80)
def drawSquare2():
t1.up()
t1.setpos(-80, -5)
t1.down()
for i in range(4):
t1.forward(80)
t1.left(90)
def drawSquare3():
t1.up()
t1.setpos(0, -5)
t1.down()
for i in range(4):
t1.forward(80)
t1.left(90)
def drawSquare4():
t1.up()
t1.setpos(80, -5)
t1.down()
t1.width(10)
# t1.begin_fill()
t1.forward(80)
t1.left(90)
t1.forward(40)
t1.left(90)
t1.forward(80)
t1.left(90)
t1.forward(40)
t1.end_fill()
t1.up()
t1.setpos(0, 40)
t1.down()
r = [10, 20, 30]
def drawCircle1():
t1.up()
t1.setpos(0, 90)
t1.down()
t1.color('white')
for x in r:
t1.circle(x)
def drawCircle2():
t1.up()
t1.setpos(-80, 90)
t1.down()
t1.color('white')
for x in r:
t1.circle(x)
def drawCircle3():
t1.up()
t1.setpos(80, 90)
t1.down()
t1.color('white')
for x in r:
t1.circle(x)
def draw_white_and_candy_disks():
# draw the first pair of disks
# set position
t1.up()
t1.setpos(0, 53)
t1.down()
# draw the white disk
t1.dot(90, '#FFFFFF')
time.sleep(1)
# set position
t1.up()
t1.setpos(0, 55)
t1.down()
# draw a cyan disk
t1.dot(70, '#FF99FF')
# draw the left pair of disks
# set position
t1.up()
t1.setpos(-80, 53)
t1.down()
# draw the white disk
t1.dot(90, '#FFFFFF')
time.sleep(1)
# set position
t1.up()
t1.setpos(-80, 55)
t1.down()
# draw the white disk
t1.dot(70, '#FF99FF')
# draw the right pair of disks
# set position
t1.up()
t1.setpos(80, 53)
t1.down()
t1.dot(90, '#FFFFFF')
time.sleep(1)
# set position
t1.up()
t1.setpos(80, 55)
t1.down()
t1.dot(70, '#FF99FF')
def drawCircles():
drawCircle1()
drawCircle2()
drawCircle3()
def drawSquares():
drawSquare1()
drawSquare2()
drawSquare3()
drawSquare4()
def draw_rectangle_squares_circles(x,y):
t1.reset()
#t1.clear()
drawSquares()
draw_white_and_candy_disks()
drawCircles()
CURSOR_SIZE = 20
FONT_SIZE = 12
FONT = ('Arial', FONT_SIZE, 'bold')
# make a turtle object
turtle = Turtle()
turtle.hideturtle()
button = Turtle()
button.hideturtle()
button.shape('circle')
button.fillcolor('red')
button.penup()
button.goto(0, 131)
button.write("Click me!", align='center', font=FONT)
button.sety(84 + CURSOR_SIZE + FONT_SIZE)
button.onclick(draw_rectangle_squares_circles)
button.showturtle()
# sety() This method is used to set the turtle's second coordinate to y, leaving the first coordinate unchanged.30 iun. 2021
win.mainloop()
' [2_xxRtJG5Uc] |