Jun-26-2018, 07:50 AM
I just begin with python and i am training with tkinter.
And i made this training script.
My OS is Windows 7 an python version 2.71
I have make a class that create a progress bar and mask it or destroy it.
button 1 create progress bar without increment "run"
button 2 increment bar "+++"
button 3 is an auto increment "update"
button 4 hide or destroy (line is in comment) "kill"
button 5 exit "quit"
If I clic in that order , every thing seem OK.
But if I clic "update" first without clic "run" first, then I call this in this def , it don t work.
I got this error;
I put some global, but it is not the problem...
Can you explain me why ?
And if you see other errors too ?
thanks !
And i made this training script.
My OS is Windows 7 an python version 2.71
I have make a class that create a progress bar and mask it or destroy it.
button 1 create progress bar without increment "run"
button 2 increment bar "+++"
button 3 is an auto increment "update"
button 4 hide or destroy (line is in comment) "kill"
button 5 exit "quit"
If I clic in that order , every thing seem OK.
But if I clic "update" first without clic "run" first, then I call this in this def , it don t work.
I got this error;
Quote:Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1542, in __call__
return self.func(*args)
File "e:\python35\job\close.py", line 56, in update
p.widget.pack()
AttributeError: progress instance has no attribute 'widget'
I put some global, but it is not the problem...
Can you explain me why ?
And if you see other errors too ?
thanks !
from Tkinter import * import sys import ttk global widget global root global p global running global progress running = 0 root = Tk() def quit(): sys.exit() class progress: global p global widget def __init__(self): self.val = 4 self.counter = 0 running = 0 print self.val print self.counter print running def creat(self): global running running = 1 print running self.widget = ttk.Progressbar(root, orient="horizontal", length=200, mode="determinate") self.widget.pack() def SetVal(self, val): self.val = val def plus(self) : global counter self.counter += self.val print self.counter self.widget.step(self.val) def kill (self): global running running=0 self.counter = 0 # self.widget.destroy() self.widget.pack_forget() def update(delay=50): global running global p global progress global widget if running==0: p.__init__ p.creat p.widget.pack() if p.counter < 98: p.plus() p.widget.after(delay, update) else: p.counter = 0 p.kill() p = progress() p.counter = 0 p.val = 4 while True: Button(root, text="run", command=p.creat).pack() Button(root, text="+++", command=p.plus).pack() Button(root, text="update", command=update).pack() Button(root, text="kill", command=p.kill).pack() Button(root, text="Quit", command=quit).pack() root.mainloop()