I want to put a decimal number instead of 1 in self.after(), but it gives an error, or how can it be made faster?
Код: Выделить всё
import tkinter as tk
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.counter = 10000
self.running = False
self.title('Einfacher down Zähler')
tk.Label(self, text="Runter zählen:").grid(row=0,column=0)
self.display = tk.Label(self, text=self.counter)
self.display.grid(row=1,column=0)
self.start_button = tk.Button(self, text="Start", command=self.start, state=tk.NORMAL, fg= "blue")
self.stop_button = tk.Button(self, text="Stop", command=self.stop, state=tk.DISABLED)
self.start_button.grid(row=0,column=1)
self.stop_button.grid(row=1,column=1)
def start(self):
self.start_button.config(state=tk.DISABLED)
self.stop_button.config(state=tk.NORMAL)
self.running = True
self.after(100,self.count_down)
def stop(self):
self.start_button.config(state=tk.NORMAL)
self.stop_button.config(state=tk.DISABLED)
self.running = False
def count_down(self):
self.counter -= 1
self.display.config(text=self.counter)
if self.counter > 0 and self.running:
self.after(1, self.count_down)
def main():
app = App()
app.mainloop()
if __name__ == '__main__':
main()
Источник: https://stackoverflow.com/questions/781 ... on-tkinter