(9) The timer control of python tkinter GUI simplified programming


The creation is not easy, please forgive me for your support, thank you!


Python tkinter GUI simplified programming article directory (click to send)

Python tkinter GUI simplified programming article directory


1. Self-introduction, packaging and usage

This series of articles will first explain the tkinter library that encapsulates python, and then will encapsulate other python GUI libraries. The details can be browsed from the first chapter, and will not be explained in the follow-up.


Second, the timer control

In the first chapter python-GUI简单化编程之基础窗口, we already import loaded package tkinter and use of other libraries, and add the 封装基础窗口, 封装顶层窗口, 数据组合框控件, 调整数据组合框控件, 按钮组合框控件, 列表显示框控件, 容器控件, 进阶版列表显示框控件code. Now, we are PythonGui.pywadding the following code package 定时器控件. Next, I will explain how to use it, and be careful not to delete the previous code.

def T_定时器控件(定时时间,定时函数,是否循环定时):
    '''
    函数说明:\n\n
    定时时间为一个int类型的数字,代表多长时间的定时时间,注意单位为ms\n\n
    定时函数为调用的外部函数名称\n\n
    是否循环定时为bool,假设定时时间为1000ms,当该参数为True时代表每1000ms执行一次,为False代表1000ms后执行,仅执行一次\n\n
    '''
    子窗口 = tk.Label()
    def 定时器():
        定时函数()
        if 是否循环定时:
            子窗口.after(int(定时时间),定时器)
    定时器()

Third, the use of package libraries

Add the following code to test.pyw to prepare for testing:

import PythonGui as GUI

主窗体 = GUI.A_建立根页面(['测试软件',400,250,'Beige'],'')
测试数据组合框1 = GUI.S_创建数据组合框控件([主窗体,0,0],['测试数据组合框1',True,False,10,12,'Beige'],['int',0,False,''])
def 外部函数():
    测试数据组合框1.set(测试数据组合框1.get()+1)
GUI.T_定时器控件(1000,外部函数,True)
主窗体.mainloop()

T_定时器控件There are three formal parameters in the function: 0. Timing time 1. Timing function 2. Whether to cycle timing
(1) The timing time is an int type number, which represents how long the timing time is. Note that the unit is: ms
(2) The timing function is the name of the external function to be called
(3) Whether the loop timing is a bool type variable, assuming that the timing time is 1000ms, when this parameter is True, it means it will be executed every 1000ms, and False means it will be executed after 1000ms. , Only once

Run the above code to generate a timer control on the main window. The timer's timing time is 1000ms, and the called function name is 外部函数, start 循环定时. In addition, in order to demonstrate the function of the timer control, a new data combo box control with the name 测试数据组合框1and initial value was created 0to display the changes of numbers:

Each of the program 1000msthe 测试数据组合框1value added1

Insert picture description here


Four, summary

If you have any suggestions, please point it out in the comment area and make progress together, thank you. ps: I usually work a lot of overtime, so I will take the time to update the following chapters.

Guess you like

Origin blog.csdn.net/baidu_37611158/article/details/115021931