資源簡介
使用python做的一個簡易畫板,能夠實現畫點、畫直線、畫多邊形、畫橢圓等功能,其中包含了對Tkinter的操作以及對于GUI的操作,希望對python初學者能夠有所幫助
代碼片段和文件信息
from?Tkinter?import?*
root?=?Tk()
c=Canvas(rootwidth=400height=400bg=‘white‘)
c.grid(row=0column=1rowspan=4)
a=[]
r=0
flag=0
def?createPoint1():
????c.bind(““createPoint)
def?createPoint(event):
????c.create_rectangle(event.xevent.yevent.x?+1event.y?+1)
????
def?createLine1():
????c.bind(““createLine)
def?createLine(event):
????global?a
????a.append((event.xevent.y))
????if?len(a)==2:
????????c.create_line(a[0]a[1])
????????a=[]
????
????
def?createPolygon1():
????c.bind(““createPolygon)
def?createPolygon(event):
????global?a
????global?r
????global?flag
????l=len(a)
????
????if?flag==0:
????????flag=1
????????a.append((event.xevent.y))
????????c.create_rectangle(event.xevent.yevent.x?+1event.y?+1)
????else?:
評論
共有 條評論