找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 862|回复: 0

[求助] 请问怎么在tkinter def pause() 函数添加暂停功能

1

主题

1

帖子

1

积分

贫民

积分
1
cancry 发表于 2022-5-9 22:12:05 | 显示全部楼层 |阅读模式
请问怎么在tkinter def pause() 函数添加暂停功能,可以使def get_pz(self)暂停和继续运作程序,谢谢!
#!/usr/bin/python
# _*_ coding=utf-8 _*_
import tkinter
from subprocess import Popen
import pyautogui
import openpyxl as vb
import openpyxl.utils as vbu
import pyperclip
import cv2
import pygame
import threading
from time import sleep
pyautogui.FAILSAFE=True
def thread_it(func,*args):
    t = threading.Thread(target=func,args=args)
    t.setDaemon(True)
    t.start()
class Caozuo():
    def __init__(self,getwsrow):
       self.l=getwsrow
    def get_pz(self):
        m=[b for b in str(self.l[2])]
        sleep(0.2)
        # os.system("pause")
        if m[0] == '1':
            print(self.l[0],self.l[2],self.l[8],self.l[9])
        elif m[0] == '5':
            print(self.l[0],self.l[2],self.l[4],self.l[8],self.l[9])
        elif m[0] == '7':
            print(self.l[0],self.l[2],self.l[4],self.l[8],self.l[9])
        else :
            print(self.l[0],self.l[2],self.l[3],self.l[4],self.l[8],self.l[9])
def run(worksheet):
    pznum = 0
    key = 0
    for row in list(worksheet.rows)[1:]:
    # 按行 把每列的值 赋值到L数组
        wsrow=[c.value for c in row]
        input_kb = cv2.waitKey(1) & 0xFF
        if input_kb == ord(' '):
            sleep(0.2)
            print('paused')
            cv2.waitKey(0)
            print('continued')
        else :
            if wsrow[0] is not None:
                number = Caozuo(wsrow)
                number.get_pz()
            else:
                pznum +=1
                print('完成第',pznum,"张凭证录入")
    exit()
def star():
    thread_it(run,ws)
def pause():
   
def stop():
    top.destroy()

if __name__=="__main__":
    wb=vb.load_workbook('序时账.xlsx')
    ws=wb.active
    top = tkinter.Tk()
    top.title("金算盘自动做账")
    thelable=tkinter.Label(top,text="需要结束程序,请先按下空格暂停")
    top.geometry('300x200') # Size 200, 200      
    startButton = tkinter.Button(top, height=3, width=20, text ="开始",
    command = star)
    pauseButton = tkinter.Button(top, height=3, width=20, text ="暂停",
    command = pause)
    stopButton = tkinter.Button(top, height=3, width=20, text ="结束",
    command = stop)
    thelable.pack()
    startButton.pack()
    pauseButton.pack()
    stopButton.pack()
    top.mainloop()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表