首页 新闻 会员 周边 捐助

python用什么库可以在当前窗口画一些多边形?

0
悬赏园豆:15 [待解决问题]

#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画图之后也会自动弹出一个窗口,求大侠支招,不胜感激!

码码码农的主页 码码码农 | 初学一级 | 园豆:90
提问于:2015-05-07 22:24
< >
分享
所有回答(1)
1

pylab库

请叫我头头哥 | 园豆:9382 (大侠五级) | 2015-05-08 09:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册