Pokemon

      在〈Pokemon〉中尚無留言

MainFrame.py

# -*- coding: utf-8 -*-

###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc
from Eve import Eve


###########################################################################
## Class MainFrame
###########################################################################

class MainFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
                          size=wx.Size(1280, 800), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
        self.boxSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.panel.SetSizer(self.boxSizer)
        self.panel.Layout()
        self.boxSizer.Fit(self.panel)
        bSizer1.Add(self.panel, 1, wx.EXPAND | wx.ALL, 5)

        self.btn = wx.Button(self, wx.ID_ANY, u"新增", wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer1.Add(self.btn, 0, wx.ALIGN_CENTER | wx.ALL, 5)

        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)
        self.Init()
    def __del__(self):
        pass
    def Init(self):
        self.Bind(wx.EVT_BUTTON, self.Btn_Click)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.ls=[]
    def Btn_Click(self, event):
        eve=Eve(self)
        self.ls.append(eve)
        self.boxSizer.Add(eve, 0 , wx.ALL, 0)
        self.Layout()
    def OnClose(self, event):
        for eve in self.ls:
            eve.Stop()
        self.Destroy();

app=wx.App()
frame=MainFrame(None)
frame.Show()
app.MainLoop()

Eve.py

import wx
import threading
import time
import random
class Eve(wx.StaticBitmap):
    def __init__(self,parent):
        wx.StaticBitmap.__init__(self, parent,
                                 wx.ID_ANY,
                                 wx.Bitmap( u"png/frame_01.png", wx.BITMAP_TYPE_ANY ),
                                 wx.DefaultPosition,
                                 wx.Size( 230,200 ),
                                 0)
        self.runFlag=True
        self.Layout()
        self.t1=threading.Thread(target=self.Task)
        self.t1.start()
    def Task(self):
        index=0
        delay=random.randint(1,100)/1000
        while self.runFlag:
            index=(index+1)%36
            wx.CallAfter(self.DrawUi,index+1)
            time.sleep(delay)
    def DrawUi(self, index):
        w,h=self.Size
        img = wx.Image('png/frame_%02d.png' % index, wx.BITMAP_TYPE_ANY)
        img = img.Scale(w, h)
        self.SetBitmap(wx.Bitmap(img))
        self.Layout()
    def Stop(self):
        self.runFlag=False

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *