tkinter 中的文本
Text in tkinter
我希望当按下“开始”按钮时,它执行代码并从 3 开始计数(3...2...1...准备就绪!),在每次和打印数字之间有延迟程序 window。我用过 tkinter。但是当我按下“开始”按钮时,我无法让倒计时出现。而且我不知道如何添加按下按钮后执行的代码。
import tkinter as tk
from tkinter import ttk
import time
class Aplicacion:
def __init__(self,master):
self.master=master
self.master.title('Title')
self.master.geometry('290x50')
self.inicializar_gui()
def inicializar_gui(self):
lbl_bienvenido=tk.Label(self.master,text='Hi!',font=('Helvetica',10))
lbl_bienvenido.place(x=0,y=0)
btn_login=tk.Button(self.master,text='Start')
btn_login['command']=self.comando
btn_login.place(x=10,y=23)
def comando(self):
entry = ttk.Entry(state=tk.DISABLED, takefocus=False)
entry.place(x=63, y=25)
entry.insert(0, "1...")
# print("3")
# time.sleep(1)
# print("2")
# time.sleep(1)
# print("1")
# time.sleep(1)
# print("Ready!")
def main ():
root = tk.Tk()
ventana = Aplicacion(root)
root.mainloop()
if __name__ == "__main__":
main()
这是一个您可以根据需要进行调整的示例:
import tkinter
root = tkinter.Tk()
txt = tkinter.Text(root)
a = 4
def countdown():
global a
if a>0:
txt.delete('1.0','end')
a -=1
txt.insert('0.0',str(a))
root.after(1000,countdown)
if a == 0 :
txt.delete('1.0','end')
txt.insert('0.0','Ready!!')
btn = tkinter.Button(root,text = 'START',command = countdown)
txt.pack()
btn.pack()
root.mainloop()
我希望当按下“开始”按钮时,它执行代码并从 3 开始计数(3...2...1...准备就绪!),在每次和打印数字之间有延迟程序 window。我用过 tkinter。但是当我按下“开始”按钮时,我无法让倒计时出现。而且我不知道如何添加按下按钮后执行的代码。
import tkinter as tk
from tkinter import ttk
import time
class Aplicacion:
def __init__(self,master):
self.master=master
self.master.title('Title')
self.master.geometry('290x50')
self.inicializar_gui()
def inicializar_gui(self):
lbl_bienvenido=tk.Label(self.master,text='Hi!',font=('Helvetica',10))
lbl_bienvenido.place(x=0,y=0)
btn_login=tk.Button(self.master,text='Start')
btn_login['command']=self.comando
btn_login.place(x=10,y=23)
def comando(self):
entry = ttk.Entry(state=tk.DISABLED, takefocus=False)
entry.place(x=63, y=25)
entry.insert(0, "1...")
# print("3")
# time.sleep(1)
# print("2")
# time.sleep(1)
# print("1")
# time.sleep(1)
# print("Ready!")
def main ():
root = tk.Tk()
ventana = Aplicacion(root)
root.mainloop()
if __name__ == "__main__":
main()
这是一个您可以根据需要进行调整的示例:
import tkinter
root = tkinter.Tk()
txt = tkinter.Text(root)
a = 4
def countdown():
global a
if a>0:
txt.delete('1.0','end')
a -=1
txt.insert('0.0',str(a))
root.after(1000,countdown)
if a == 0 :
txt.delete('1.0','end')
txt.insert('0.0','Ready!!')
btn = tkinter.Button(root,text = 'START',command = countdown)
txt.pack()
btn.pack()
root.mainloop()