Python Forum
[Tkinter] newbie with python and tkinter
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] newbie with python and tkinter
#1
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;
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()
Reply


Messages In This Thread
newbie with python and tkinter - by pat - Jun-26-2018, 07:50 AM
RE: newbie with python and tkinter - by wuf - Jun-26-2018, 01:57 PM
RE: newbie with python and tkinter - by pat - Jun-26-2018, 02:38 PM
RE: newbie with python and tkinter - by wuf - Jun-26-2018, 03:44 PM
RE: newbie with python and tkinter - by pat - Jun-26-2018, 05:53 PM
RE: newbie with python and tkinter - by wuf - Jun-26-2018, 06:31 PM
RE: newbie with python and tkinter - by pat - Jun-26-2018, 07:11 PM
RE: newbie with python and tkinter - by wuf - Jun-26-2018, 07:18 PM
RE: newbie with python and tkinter - by pat - Jun-26-2018, 07:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Python Newbie MartyH 6 2,814 May-13-2020, 07:07 PM
Last Post: MartyH
  Newbie question with Tkinter Entry mariolopes 2 2,301 Oct-12-2019, 11:02 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020