#encoding=utf-8
import wx
import turtle
class PaintWindow(wx.Window):
def __init__(self,parent,id,pos,size):
wx.Window.__init__(self,parent,id,pos,size)
turtle.color("purple")
turtle.pensize(5)
turtle.goto(0,0)
turtle.speed(10)
for i in range(6):
turtle.forward(100)
turtle.right(144)
turtle.up()
turtle.forward(100)
turtle.goto(-150,-120)
turtle.color("red")
turtle.write("Done")
class MyFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,'Rectangle Arrange',size=(600,600))
sbutton=wx.Button(self,label="Create",pos=(420,5),size=(80,25))
wx.StaticText(self,-1,"Length:",pos=(5,5))
self.length=wx.TextCtrl(self,pos=(50,5),size=(50,25))
wx.StaticText(self,-1,"Height:",pos=(100,5))
self.height=wx.TextCtrl(self,pos=(145,5),size=(50,25))
wx.StaticText(self,-1,"Locate x:",pos=(195,5))
self.winx=wx.TextCtrl(self,pos=(250,5),size=(50,25))
wx.StaticText(self,-1,"Locate y:",pos=(300,5))
self.winy=wx.TextCtrl(self,pos=(350,5),size=(50,25))
sbutton.Bind(wx.EVT_BUTTON,self.OnClick,sbutton)
self.paint=PaintWindow(self,-1,(0,0),(0,0))
self.flg=0
def OnClick(self,event):
self.flg+=1
winsize=(int(self.length.GetValue()),int(self.height.GetValue()))
winpos=(int(self.winx.GetValue()),int(self.winy.GetValue()))
"""
self.image=Image.new("RGB",size,"white")
self.image.save(r"D:\save.png")
self.image=Image.open(r"D:\save.png")
draw=ImageDraw.Draw(self.image)
draw.line((0, 0) + self.image.size, fill=128)
draw.line((0, self.image.size[1], self.image.size[0], 0), fill=128)
self.image.save(r"D:\save.png")
"""
if(self.flg!=0):
self.paint.Destroy()
self.flg=0
self.paint=PaintWindow(self,-1,winpos,winsize)
if __name__=="__main__":
app=wx.App()
frame=MyFrame(None)
frame.Show()
app.MainLoop()
如上面的代码,我想在PaintWindow里动态画出一些多边形,该用什么库,frame主要是用来创建大小位置可以自己设定的PaintWindow。初学python,不知道该怎么在PaintWindow里画多边形,PIL是画在图片里并保存,turtle画图之后也会自动弹出一个窗口,求大侠支招,不胜感激!
pylab库