
Lv.1
签名:已润
在 【Python作品分享】一键画图V3.0.17 中回复
from tkinter import*
from tkinter.colorchooser import*
from tkinter import messagebox
#说明
introduction = Tk()
introduction.withdraw()
messagebox.showinfo(title='说明',
message='此为一个画图软件,灵感来自于人工智能————御眼重明,目前仍在开发阶段,现在版本为V7 .0(点击确定继续)')
messagebox.showinfo(title='说明',
message='用鼠标操控画笔,按住滑动便可画出图案,可以设置线条颜色和填充颜色,左边是形状按钮,还有背景颜色设置,点击便可画出不同的形状(点击确定开始)')
#设置背景颜色
#创建按钮和画布
window = Tk()
window.configure(background="gray", cursor="fleur", width=1000, height=900)
window.title("绘图软件 V.7.0")
window.geometry("2000x2000")
instruction = Label(window, text="用鼠标左键在下方画布上绘画",
background="gray", cursor="shuttle")
instruction.pack()
BlackButton = Button(window, bg="black", fg="white",
text="背景黑色", cursor="fleur")
BlackButton.pack()
BlackButton.place(x=10, y=450)
whiteButton = Button(window, bg="white",
text="背景白色", cursor="fleur")
whiteButton.pack()
whiteButton.place(x=10, y=420)
fillButton = Button(window, bg="blue", fg="white", activebackground="blue",
activeforeground="white", text="填充颜色", cursor="gumby gumby")
fillButton.pack()
fillButton.place(x=10, y=350)
colorButton = Button(window, bg="skyblue", activebackground="skyblue",
text="线条颜色", cursor="gumby gumby")
colorButton.pack()
colorButton.place(x=10, y=380)
rectButton = Button(window, bg="green", text="方形",
cursor="dotbox")
rectButton.pack()
rectButton.place(x=10, y=310)
lineButton = Button(window, bg="red",
text="铅笔", cursor="gumby gumby")
lineButton.pack()
lineButton.place(x=10, y=270)
circleButton = Button(window, bg="orange",
text="圆圈", cursor="circle")
circleButton.pack()
circleButton.place(x=10, y=230)
explosiveButton = Button(window, bg="pink",
text="线段", cursor="gumby gumby")
explosiveButton.pack()
explosiveButton.place(x=10, y=190)
clearButton = Button(window, bg="yellow",
text="清除", cursor="dotbox")
clearButton.pack()
clearButton.place(x=10, y=150)
myCanvas = Canvas(window, width=1300, height=1000,
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)
#改变画笔颜色的程序
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()
2019-08-24T17:52:12 点赞:0
在 【Python作品分享】python 画画 中回复
试试我的绘图软件
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()
2019-08-29T11:21:26 点赞:0