tkformat.py

#! /usr/bin/python3
# -*- coding: utf-8 -*-
# File: tkformat.py

from tkinter import *
from tkinter import messagebox
import time
import sys


root = None

def die():
   root.destroy()
   sys.exit(0)

def warten(n):
   time.sleep(n)


if __name__ == "__main__":
    root = Tk()

    root.protocol('WM_DELETE_WINDOW',die)
    root.withdraw()
    root.title("Have fun!")

    if messagebox.askyesno("Format.py","Festplatte formatieren?"):
        messagebox.showinfo("Formatieren . . .","Ok, wir fangen an . . .")
    else:
        messagebox.showinfo("Formatieren . . ."," I'm sorry, \n cancel not yet \n implemented . . .")


    frm = Frame(root,width=600)
    frm.pack()
    w = Label(frm, text="\n\n   Wir formatieren . . .   \n\n")
    w.pack()
    scale = Scale(frm,label='Das nennt man Fortschritt:',from_=0, to=100, orient='horizontal',tickinterval=25,length=200)
    scale.pack()

    root.deiconify()

    for i in range(11):
       scale.set(i*10)
       scale.update()
       if i < 10:
          warten(1)

    if messagebox.showinfo("Formatieren . . ."," . . . war erfolgreich :-)"):
       die()

    root.mainloop()

Fenster schließen