2018年12月12日水曜日

wxpython ウィンドウにカウンター表示(1~+1していく)


E:\MyBackups\goolgedrive\myprg_main\python_my_prg\wxpython\timer.py


# coding: UTF-8

#wxウィンドウにカウンター表示(1~+1していく)
#http://stackoverflow.com/questions/7684934/wxpython-using-wxtimer-my-box-doesnt-move
#タイマーの使用 <http://d.hatena.ne.jp/lolloo-htn/20090804/1249343399>

import wx

class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="timer", size=(300,200))
#textctrl(self)
self.i = 1
self.text = str(self.i)
self.TxtCtr = wx.TextCtrl(self, -1, self.text, pos=(20,20), size=(150,-1))
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(100)

def OnTimer(self, event):
#SetValue
self.i += 1
self.text = str(self.i)
self.TxtCtr.SetValue(self.text)
print self.i

if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MainFrame()
frame.Show(True)
app.MainLoop()

0 件のコメント:

コメントを投稿

About

参加ユーザー

連絡フォーム

名前

メール *

メッセージ *

ブログ アーカイブ

ページ

Featured Posts