Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在python中显示计时器_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x 如何在python中显示计时器

Python 3.x 如何在python中显示计时器,python-3.x,tkinter,Python 3.x,Tkinter,嘿,我正在制作一个记录桌面屏幕的程序 所以我想做的是当我在Gui窗口中单击开始按钮(TkinterGUI)时 它应该启动一个计时器,如3,2.1.直接在桌面屏幕上使用大字体,而不是在tkinter窗口上。然后我的功能就应该启动了 我该怎么做 import tkinter as tk from tkinter import * root = Tk() root.title("our program") start_cap =tk.button(text='start recording' com

嘿,我正在制作一个记录桌面屏幕的程序

所以我想做的是当我在Gui窗口中单击开始按钮(TkinterGUI)时

它应该启动一个计时器,如3,2.1.直接在桌面屏幕上使用大字体,而不是在tkinter窗口上。然后我的功能就应该启动了

我该怎么做

import tkinter as tk
from tkinter import *

root = Tk()
root.title("our program")
start_cap =tk.button(text='start recording' command=start_capute)
start_cap.pack()
root.mainloop()
这里没有提到函数和整个代码,因为它们不是必需的。代码运行良好,我只想在其中添加一个新的计时器功能

一个简单的例子:

import tkinter as tk
# from tkinter import *

def Start():

    def Count(Number):
        if Number == -1:
            win.withdraw()
            print("Start") # what you want to do
            return False
        NumberLabel["text"] = Number
        win.after(1000,Count,Number-1)
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    win = tk.Toplevel()
    win.geometry("+%d+%d"%((screen_width-win.winfo_width())/2,(screen_height-win.winfo_height())/2)) # make it in the center.
    win.overrideredirect(1)
    win.wm_attributes('-topmost',1) # top window
    win.wm_attributes('-transparentcolor',win['bg']) # background transparent.
    NumberLabel = tk.Label(win,font=("",40,"bold"),fg='white')
    NumberLabel.pack()
    win.after(0,lambda :Count(3))
    win.mainloop()

root = tk.Tk()
root.title("our program")
start_cap = tk.Button(text='start recording',command=Start)
start_cap.pack()
root.mainloop()
一个简单的例子:

import tkinter as tk
# from tkinter import *

def Start():

    def Count(Number):
        if Number == -1:
            win.withdraw()
            print("Start") # what you want to do
            return False
        NumberLabel["text"] = Number
        win.after(1000,Count,Number-1)
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    win = tk.Toplevel()
    win.geometry("+%d+%d"%((screen_width-win.winfo_width())/2,(screen_height-win.winfo_height())/2)) # make it in the center.
    win.overrideredirect(1)
    win.wm_attributes('-topmost',1) # top window
    win.wm_attributes('-transparentcolor',win['bg']) # background transparent.
    NumberLabel = tk.Label(win,font=("",40,"bold"),fg='white')
    NumberLabel.pack()
    win.after(0,lambda :Count(3))
    win.mainloop()

root = tk.Tk()
root.title("our program")
start_cap = tk.Button(text='start recording',command=Start)
start_cap.pack()
root.mainloop()

无需使用全局
编号
。将其作为参数传递给
Count()
。使用
win.after(1000,Count,Number-1)
而不是lambda和
Number-=1
。无需使用全局
Number
。将其作为参数传递给
Count()
。使用
win.after(1000,Count,Number-1)
而不是lambda和
Number-=1
。此网站上有几十个与计时器和时钟相关的问题。在提出这个问题之前,你做过任何研究吗?这个网站上有几十个关于计时器和时钟的问题。问这个问题之前你做过研究吗?