猫史档案馆


【Python作品分享】python 画画

用户:****查看:0 回复:2 评论:0 创建时间:2019-08-29T10:11:18


【作品展示】

center_image

 

【作品介绍】

画画

 

【作品源代码】

import turtle
import time
turtle.pensize(2)
turtle.bgcolor("black")
colors=["red","yellow","purple","blue"]

for x in range(400):
    turtle.forward(2*x)
    turtle.color(colors[x%4])
    turtle.left(91)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
QBZ_QBZ_

加油!

 

点赞0


评论


QBZ_QBZ_

试试我的绘图软件

from tkinter import*
from tkinter.colorchooser import*
from tkinter import messagebox


# 主程序
# 设置背景颜色
# 创建按钮和画布

window = Tk()
window.configure(background="gray", cursor="fleur", width=1000, height=1000)
window.title("绘图软件 7.0")
window.geometry("2000x2000")

instruction = Label(window, text="用鼠标左键在下方画布上绘画",
                    background="gray", cursor="shuttle",)
instruction.pack()

speak = Button(window, bg="orange", fg="black",
            text="帮助", cursor="fleur", bd="5px", activebackground="orange",)
speak.pack()
speak.place(x=10, y=110)

BlackButton = Button(window, bg="black", fg="white",
                    text="背景黑色", cursor="fleur", bd="5px")
BlackButton.pack()
BlackButton.place(x=10, y=510)

whiteButton = Button(window, bg="white",
                    text="背景白色", cursor="fleur", bd="5px")
whiteButton.pack()
whiteButton.place(x=10, y=470)

fillButton = Button(window, bg="blue", fg="white", activebackground="blue",
                    activeforeground="white", text="填充颜色", cursor="gumby gumby", bd="5px")
fillButton.pack()
fillButton.place(x=10, y=430)

colorButton = Button(window, bg="skyblue", activebackground="skyblue",
                    text="线条颜色", cursor="gumby gumby", bd="5px")
colorButton.pack()
colorButton.place(x=10, y=390)

rectButton = Button(window, bg="green", text="方形",
                    cursor="dotbox", bd="5px")
rectButton.pack()
rectButton.place(x=10, y=310)

lineButton = Button(window, bg="red",
                    text="铅笔", cursor="gumby gumby", bd="5px")
lineButton.pack()
lineButton.place(x=10, y=270)

circleButton = Button(window, bg="orange",
                    text="圆圈", cursor="circle", bd="5px")
circleButton.pack()
circleButton.place(x=10, y=230)

explosiveButton = Button(window, bg="pink",
                        text="线段", cursor="gumby gumby", bd="5px")
explosiveButton.pack()
explosiveButton.place(x=10, y=190)

clearButton = Button(window, bg="yellow",
                    text="清除", cursor="dotbox", bd="5px")
clearButton.pack()
clearButton.place(x=10, y=150)

myCanvas = Canvas(window, width=1600, height=900,
                cursor="spraycan", bg="white")
myCanvas.pack()

# 背景颜色
def Black(event):
    myCanvas.configure(bg="black")
    window.update()


BlackButton.bind("<Button-1>", Black)


def white(event):
    myCanvas.configure(bg="white")
    window.update()


whiteButton.bind("<Button-1>", white)

#帮助
#说明
def Help(event):
    introduction = Tk()
    introduction.withdraw()
    messagebox.showinfo(title='说明',
                        message='此为一个画图软件,灵感来自于人工智能————御眼重明,目前仍在开发阶段,现在版本为7 .0(点击确定继续)')
    messagebox.showinfo(title='说明',
                        message='用鼠标操控画笔,按住滑动便可画出图案,可以设置线条颜色和填充颜色,左边是形状按钮,还有背景颜色设置,点击便可画出不同的形状(点击确定开始)')


speak.bind("<Button-1>", Help)

# 改变画笔颜色的程序
myColor = "black"
myShape = "line"
myfill = "white"

# 定义x,y轴
def pen_down(event):
    global prevX
    global prevY
    prevX = event.x
    prevY = event.y


myCanvas.bind("<ButtonPress-1>", pen_down)

# 画线的程序
def draw(event):
    global prevX
    global prevY
    if myShape == "line":
        myCanvas.create_line(prevX, prevY, event.x, event.y, fill=myColor)
        prevX = event.x
        prevY = event.y

myCanvas.bind("<B1-Motion>", draw)


def pen_up(event):
    if myShape == "circle":
        myCanvas.create_oval(prevX, prevY, event.x,
                            event.y, outline=myColor, width=5, fill=myfill)
    if myShape == "rectangle":
        myCanvas.create_rectangle(
            prevX, prevY, event.x, event.y, outline=myColor, width=5, fill=myfill)
    if myShape == "explosive":
        myCanvas.create_polygon(prevX, prevY, event.x,
                                event.y, outline=myColor, width=5, fill=myfill)


myCanvas.bind("<ButtonRelease-1>", pen_up)

# 改变颜色
def pick_color(event):
    global myColor
    myColor = askcolor()
    myColor = myColor[1]

colorButton.bind("<Button-1>", pick_color)


def pick_fill(event):
    global myfill
    myfill = askcolor()
    myfill = myfill[1]


fillButton.bind("<Button-1>", pick_fill)

# 清除画布的程序
def clear(event):
    myCanvas.delete(ALL)


clearButton.bind("<Button-1>", clear)


def set_line(event):
    global myShape
    myShape = "line"


lineButton.bind("<Button-1>", set_line)


def set_rect(event):
    global myShape
    myShape = "rectangle"


rectButton.bind("<Button-1>", set_rect)


def set_circle(event):
    global myShape
    myShape = "circle"


circleButton.bind("<Button-1>", set_circle)


def set_explosive(event):
    global myShape
    myShape = "explosive"


explosiveButton.bind("<Button-1>", set_explosive)

window.mainloop()

点赞0


评论