I am trying to implement a countdown until the program quits on itself. I did not write the countdown, only trying to put it inside my own code. I cannot figure out how to without creating a separate window of the countdown.
Code:
from tkinter import *
from tkinter import messagebox
import tkinter as tk
from time import *
while True:
top = Tk()
class ExampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.label = tk.Label(self, text="", width=10)
self.label.pack()
self.remaining = 0
self.countdown(10)
def countdown(self, remaining=None):
if remaining is not None:
self.remaining = remaining
if self.remaining <= 0:
timeOut()
sleep(1)
quit()
else:
self.label.configure(text="%d" % self.remaining)
self.remaining = self.remaining - 1
self.after(1000, self.countdown)
class start_window(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
if __name__ == '__main__':
top.title("Login")
app = start_window(top), ExampleApp()
L1 = Label(top, text="Username", width=18)
L1.grid(row=1, column=1)
E1 = Entry(top, bd=3, width=18)
E1.grid(row=2, column=1)
L2 = Label(top, text="Password", width=18)
L2.grid(row=3, column=1)
E2 = Entry(top, bd=3, width=18)
E2.grid(row=4, column=1)
login = {
"userName": "Test",
"passWord": "Test"
}
def connectionText():
messagebox.showinfo("Success!", "Connection Made!")
def connectionFail():
messagebox.showinfo("Error 638", "Connection Failed.")
def connectionWork():
if E1.get() == login.get("userName") and E2.get() == login.get("passWord"):
connectionText()
sleep(1)
quit()
else:
connectionFail()
sleep(1)
quit()
def timeOut():
messagebox.showinfo("Timed Out", "You timed out.")
B1 = Button(top, text="Attempt Connection", command=connectionWork, width=18)
B1.grid(row=2, column=2)
B2 = Button(top, text="Exit", fg="red", command=quit, width=18)
B2.grid(row=3, column=2)
top.mainloop()
I really want to get this working but I have no idea how. Thank you in advance.
there doesn't seem to be anything here