wenn ich meine Gui über das das "X" beende bekomme ich immer einen Fehler angegeben. Sobald ich es aber über root.mainloop() programmiere und meinen zyklischen Aufruf nicht v verwende funktioniert es.
Könnte mir jemand Hilfe geben woran das liegt?
Beste Grüße
Code: Alles auswählen
from tkinter import *
from tkinter import messagebox
import time
from datetime import datetime
def on_closing():
if messagebox.askokcancel("Beenden", "Wollen Sie wirklich das Programm beenden?"):
global running
running = FALSE
root.destroy()
# Main Window
root = Tk()
root.geometry("595x500+300+300")
root.wm_resizable(width=False, height=False)
root.title("TestGUI")
menu = Menu(root)
root.config(menu=menu)
statusbar = Label(root, text="", bd=1, relief=SUNKEN, anchor=W)
statusbar.pack(side=BOTTOM, fill=X)
running = True
def main():
while running:
root.update_idletasks()
root.update()
time.sleep(0.5)
lt = '{:%d.%m.%Y %H:%M:%S}'.format(datetime.now())
statusbar['text'] = lt
root.protocol("WM_DELETE_WINDOW", on_closing)
if __name__ == '__main__':
main()
Code: Alles auswählen
D:\Privat\PyCharm\Countdown\venv\Scripts\python.exe C:/Users/xxx/.PyCharmCE2019.3/config/scratches/scratch_13.py
Traceback (most recent call last):
File "C:/Users/xxx/.PyCharmCE2019.3/config/scratches/scratch_13.py", line 38, in <module>
main()
File "C:/Users/xxx/.PyCharmCE2019.3/config/scratches/scratch_13.py", line 32, in main
statusbar['text'] = lt
File "D:\Privat\Python\lib\tkinter\__init__.py", line 1648, in __setitem__
self.configure({key: value})
File "D:\Privat\Python\lib\tkinter\__init__.py", line 1637, in configure
return self._configure('configure', cnf, kw)
File "D:\Privat\Python\lib\tkinter\__init__.py", line 1627, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!label"
Process finished with exit code 1