import Tkinter
class mybutton:#定义按钮类
def __init__(self,root,canvas1,label1,type):#类初始化canvas1,label1是MyCanvals,mylabel的实例,因此可以使用类中的方法
self.root=root#保存引用值
self.canvas1=canvas1
self.label1=label1
if type==0:#根据类型创建按钮
button=Tkinter.Button(root,text='huaxian',command=self.DrawLine)
elif type==1:
button=Tkinter.Button(root,text='huashanxing',command=self.DrawArc)
elif type==2:
button=Tkinter.Button(root,text='huajuxing',command=self.DrawRec)
else:
button=Tkinter.Button(root,text='huatuoyuan',command=self.DrawOval)
button.pack(side='left')
def DrawLine(self):#DrawLine按钮事件处理函数
self.label1.text.set('Draw Line')
self.canvas1.SetStatus(0)#把status赋值,便于根据status的值进行画图
def DrawArc(self):
self.label1.text.set('Draw Arc')
self.canvas1.SetStatus(1)
def DrawR
使用事件处理创建一个简单的绘图实例程序 python
最新推荐文章于 2024-06-21 15:26:30 发布