马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# -*- coding:utf-8 -*-
from tkinter import *
from tkinter import colorchooser
import tkinter
win=tkinter.Tk()
win.title("简单小部件!")
win.geometry('250x120+50+10')
label=tkinter.Label(win,\
text='欢迎来到我的世界!',\
font='宋体',\
fg='#0000ff'
)
label.pack()
def eBtnClickme():
root = Tk()
root.title("画图")
var = IntVar()
var.set(1)
w = Canvas(root, width=1350, height=700)
w.pack()
THICK = 7
THIN = 2
MEDIUM = 4
THICKNESS = THIN
COLOR = "#ff0000"
def paint(event):
x1, y1 = (event.x - THICKNESS), (event.y - THICKNESS)
x2, y2 = (event.x + THICKNESS), (event.y + THICKNESS)
w.create_oval(x1, y1, x2, y2, fill=COLOR)
def thickness(tn):
global THICKNESS
THICKNESS = tn
def choosecolor():
global COLOR
COLOR = colorchooser.askcolor()[1]
mb = Menu(root)
thmenu = Menu(mb, tearoff=False)
thmenu.add_radiobutton(variable=var, value=1, label="细",
command=lambda: thickness(THIN))
thmenu.add_radiobutton(variable=var, value=2, label="中",
command=lambda: thickness(MEDIUM))
thmenu.add_radiobutton(variable=var, value=3, label="粗",
command=lambda: thickness(THICK))
mb.add_cascade(label="调整画笔粗细", menu=thmenu)
colormenu = Menu(mb, tearoff=False)
colormenu.add_command(label="调整画笔颜色", command=choosecolor)
mb.add_cascade(label="选择颜色", menu=colormenu)
root.config(menu=mb)
w.bind("<B1-Motion>", paint)
w.bind("<B3-Motion>", paint)
btn1=tkinter. Button (win,text ='画布!',bg='green' , command=eBtnClickme)
btn1.pack()
mainloop()
|