martedì 21 agosto 2012

Esempio GUI con TKinter

Un esempio di uso della GUI Tkinter su Python 3.2 (da confrontare con questo post)



------------------------------------------
import tkinter as tk
from tkinter import ttk

class App:


    def __init__(self):
        self.root = tk.Tk()

        self._job = None
        self.root.title("Progress Bar")

        self.frame = tk.Frame(self.root, width=200, height=10)
        self.frame.pack()
       
        self.slider = tk.Scale(self.root, from_=0, to=100,
                               orient="horizontal",
                               command=self.updateValue, length=200)
        self.slider.pack()

        self.lab = tk.Label(self.root, text="         ")
        self.lab.pack()
   
       
        self.pbar = ttk.Progressbar(self.root, length=200,mode="determinate", maximum=100)
        self.pbar.pack(padx=5, pady=5)
        self.pbar.start
       
        self.root.mainloop()

    def updateValue(self, event):
        if self._job:
            self.root.after_cancel(self._job)
        self.pbar["value"] = int(self.slider.get())
        self.lab.config(text=str(self.slider.get()))
       

app=App()

------------------------------------------