'Text in tkinter
I want that when the "Start" button is pressed, it executes code and counts from 3 (3... 2... 1... Ready!), with delay between each and printing the numbers in the program window. I used tkinter. But I can't get the countdown to appear when I press the "Start" button. And I don't know how to add the code that is executed after pressing the button.
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
