关于定时器的一个简单应用,包含了定时器的启动、停止
小萌新一个,抛砖引玉,各位大神有可以开源什么案例求分享~~
界面如下:
代码如下
#coding=utf-8
import sys
import os
from os.path import abspath, dirname
sys.path.insert(0,abspath(dirname(__file__)))
import tkinter
from tkinter import *
import Fun
uiName="TimerExamples"
ElementBGArray={}
ElementBGArray_Resize={}
ElementBGArray_IM={}
run_count = 0
#Form 'Form_1's Load Event :
def Form_1_onLoad(uiName,threadings=0):
pass
#Timer 'Timer_1's Timer Event :
def Timer_1_onTimer(uiName,widgetName,count=0):
#这面运行再定时器运行时的一些方法
global run_count
run_count += 1
insert_text(run_count)
#Button 'Button_1' 's Command Event :
def Button_1_onCommand(uiName,widgetName,threadings=0):
#获取定时器组件
Timer_1=Fun.GetElement(uiName,'Timer_1')
#设置定时器运行周期,毫秒计算,1000毫秒为1秒
Timer_1.SetInterval(1000)
#使定时器开始运行
Timer_1.Start()
def insert_text(run_count):
Fun.InsertText(uiName,'Text_1',position=tkinter.END,textValue=f'定时器运行插入文本,当前第{run_count}次\n',tag='')
#Button 'Button_2' 's Command Event :
def Button_2_onCommand(uiName,widgetName,threadings=0):
Timer_1=Fun.GetElement(uiName,'Timer_1')
#停止定时器运行
Timer_1.Stop()
Fun.InsertText(uiName,'Text_1',position=tkinter.END,textValue='定时器结束插入文本\n',tag='')
感谢大佬分享源码
登录后才能回复帖子