您的位置:首页 > 编程语言 > Python开发

python 简单实现 图片百叶窗效果

2014-08-15 21:38 1396 查看
#coding:utf-8
'''
Created on 2014年3月3日

@author: silence
'''

#coding:utf-8

import wx
import os

ID_START=wx.NewId()
ID_STOP=wx.NewId()
ID_CLOSE=wx.NewId()

class Frame(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title,size=(580,400))
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.SetBackgroundColour(wx.BLACK)
self.y_axis=list()
for i in range(10):
self.y_axis.append((i+2)*25)
self.first_height=0
self.run=False
self.OnInit(None)
path='exam049.bmp'
self.myfile=self.modifyPath(path)
self.image=wx.Image(self.myfile,wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.bt_start=wx.Button(self,id=ID_START,label=u"开始",pos=(470,100),size=(60,25))
self.bt_close=wx.Button(self,id=ID_CLOSE,label=u"退出",pos=(470,140),size=(60,25))
self.bt_stop=wx.Button(self,id=ID_STOP,label=u"停止",pos=(470,180),size=(60,25))

self.Bind(wx.EVT_BUTTON,self.OnClose,id=ID_CLOSE)
self.Bind(wx.EVT_BUTTON,self.OnStart,id=ID_START)
self.Bind(wx.EVT_BUTTON,self.OnStop,id=ID_STOP)
self.OnTimer(None)

self.timer = wx.Timer(self)
self.timer.Start(100)
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnTimer(self, evt):
if self.run:
self.Refresh()
def OnClose(self,event):
self.Destroy()
def OnStart(self,event):
self.run=True
event.Skip()
def OnStop(self,event):
self.run=False
event.Skip()
def modifyPath(self,path):
path='/'+path
l=path.split('/')
path='\\'.join(["%s" %n for n in l])
return os.getcwd()+path
def OnInit(self,event):
self.first_height=0
def OnPaint(self, evt):
w=self.image.GetWidth()
pdc = wx.BufferedPaintDC(self)
try:
dc = wx.BufferedDC(pdc)
except:
dc = pdc
dc.SetBrush(wx.BLACK_BRUSH)
dc.Clear()
pt=(30,50)
dc.DrawBitmapPoint(self.image,pt)
for i in range(10):
dc.DrawRectangle(x=30,y=self.y_axis[i],width=w,height=self.first_height)
if self.first_height>25:
self.OnInit(None)
else:
self.first_height+=1

class App(wx.App):
def OnInit(self):
frame=Frame(parent=None, id=wx.ID_ANY, title=u"图片百叶窗")
frame.Show(True)
return True
def OnExit(self):
self.Exit()
return True

def main():
app=App()
app.MainLoop()

if __name__=="__main__":
main()


效果图



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: