Bootstrap

tkinter实现简单画图

一 代码

import tkinter
from PIL import Image
app = tkinter.Tk()
app.title('My Paint----by cakin24')
app['width'] = 800
app['height'] = 600
#控制是否允许画图的变量,1:允许,0:不允许
yesno = tkinter.IntVar(value=0)
#控制画图类型的变量,1:曲线,2:直线,3:矩形,4:文本,5:橡皮
what = tkinter.IntVar(value=1)
#记录鼠标位置的变量
X = tkinter.IntVar(value=0)
Y = tkinter.IntVar(value=0)
#前景色
foreColor = '#000000'
backColor = '#FFFFFF'
#创建画布
image = tkinter.PhotoImage()
canvas = tkinter.Canvas(app, bg='white', width=800, height=600)
canvas.create_image(800, 600, image=image)
#鼠标左键单击,允许画图
def onLeftButtonDown(event):
    yesno.set(1)
    X.set(event.x)
    Y.set(event.y)
    if what.get()==4:
        canvas.create_text(event.x, event.y, text=text)
canvas.bind('<Button-1>', onLeftButtonDown)
#记录最后绘制图形的id
la
;