problem in python function --Name-error

ns56645 ns56645 at swt.edu
Sat Apr 29 19:19:09 CEST 2000


Hi,

I am sending you the whole code of my program as an attachment.  But the
error lies in def drawCanvas( ): I have emphasized the error. The error
says nameError frame1. The output of my program looks similar to
http://www.swt.edu/~ns56645.
Could you please help me with the error.






-------------- next part --------------
import sys
sys.path[:0] = ['../']



from Tkinter import *
import Pmw

class Schedule:

       def __init__(self,master):
	global mycourses
	mycourses = [1000, 1203, 3224, 1244, 3453, 3342, 2232, 2131, 2342, 2342, 2222, 5544, 5232]
	time = [8.00, 9.30, 11.00, 12.30, 2.00, 3.30, 5.00, 6.30]

#def create_frames(master):
    # relief and borderwidth arguments make frames visible

##############   Create four frames ##############################################

   	frame1 = Frame(master, relief='sunken', borderwidth=2)
    	frame2 = Frame(master, relief='sunken', borderwidth=1)
    	frame3 = Frame(master, relief='sunken', borderwidth=1)
    	frame4 = Frame(master, relief='sunken', borderwidth=1)

    	frame1.place(relx=0, rely=0, relwidth=1, relheight=0.70)
	frame2.place(relx=0, rely=0.70, relwidth=0.40, relheight=0.30)
    	frame3.place(relx=0.40, rely=0.70, relwidth=0.30, relheight=0.30)
    	frame4.place(relx=0.70, rely=0.70, relwidth=0.30, relheight=0.30)
       	
############### Canvas for Days in Frame 1 ##########################################

	self.days=Canvas(frame1,width=50, height=430, bg='white')
	self.drawDays()
	self.days.grid(row=0, column=0, rowspan=7, sticky=W+N)
	

################# Canvas for Time in frame 1 #########################################

	self.time = Canvas(frame1, width=800, height=30, bg='white')
	self.time = Canvas(width=600, height=30, bg='white')
	self.drawTime()
	self.time.grid(row=0, column=1)

############## DRAW CANVASES IN FRAME 1  ###############################################

	self.drawCanvas()

###################   COMBOBOX FOR COURSES IN FRAME 2    ################################################


        group = Pmw.Group(frame2, tag_text = 'Selection Criteria')
        group.pack(fill = 'both', expand = 1, padx = 15, pady = 10)

	# Create and pack the dropdown ComboBox.
        courses = [' ',4310, 5389, 4328,3358, 5310, 7000]
	dropdown1 = Pmw.ComboBox(group.interior(),
                label_text = 'Courses      ',
	        labelpos = 'w',
		listheight = 150,
#		buttonaspect = 2.0,
                #selectioncommand = self.changeColour,
		scrolledlist_items = courses,
        )
#	dropdown1.grid(row=1)
        dropdown1.pack(pady=5)

	# Display the first colour.
	first = courses[0]
	dropdown1.selectitem(first)
	#self.changeText(first)


###############  COMBOBOX FOR ROOMS  IN FRAME 2      #######################################################


	# Create and pack the dropdown ComboBox.
        rooms = [' ','DH241', 'DH113', 'DH240','DH213']
	dropdown2 = Pmw.ComboBox(group.interior(),
                label_text = 'Rooms       ',
	        labelpos = 'w',
                #selectioncommand = self.changeColour,
		scrolledlist_items = rooms,
        )
#	dropdown2.grid(row=2)
	dropdown2.pack()
	# Display the first colour.
	first = rooms[0]
	dropdown2.selectitem(first)
	#self.changeColour(first)

#################       COMBOBOX FOR PROFESSORS IN FRAME2        ################################


	# Create and pack the dropdown ComboBox.
        instruc = [' ','Davis', 'Mccabe', 'Kaikhah', 'Peng', 'Hall']
	dropdown3 = Pmw.ComboBox(group.interior(),
                label_text = 'Instructors ',
	        labelpos = 'w',
		hull_width=5,
                #selectioncommand = self.changeColour,
		scrolledlist_items = instruc,
        )
#	dropdown2.grid(row=2)
	dropdown3.pack()
	# Display the first colour.
	first = instruc[0]
	dropdown3.selectitem(first)
	#self.changeColour(first)


######################COMBOBOX FOR LABS IN FRAME 2 ################################################


	# Create and pack the dropdown ComboBox.
        labs = [' ','DH231', 'DH235', 'DH231C', 'DH231B']
	dropdown4 = Pmw.ComboBox(group.interior(),
                label_text = 'Labs          ',
	        labelpos = 'w',
                #selectioncommand = self.changeColour,
		scrolledlist_items = labs,        )
#	dropdown2.grid(row=2)
	dropdown4.pack()
	# Display the first colour.
	first = labs[0]
	dropdown4.selectitem(first)
	#self.changeColour(first)



####         Frame 3  Radio Buttons        #####################################################

        # Create the "Location" contents of the page.
        group = Pmw.Group(frame3, tag_text = 'Location')
        group.pack(fill = 'both', expand = 1, padx = 15, pady = 10)

	v1 = IntVar()
	v1.set(3) # initialize
        rb1 = Radiobutton(group.interior(), text = 'SWT', variable=v1, value=1)
        rb1.grid(row = 0, column = 0)
        rb2 = Radiobutton(group.interior(), text = 'WHS', variable=v1, value=2)
        rb2.grid(row = 0, column = 1)
        rb3 = Radiobutton(group.interior(), text = 'BOTH', variable=v1, value=3)
        rb3.grid(row = 0, column = 2)
	

        # Create the "Level" contents of the page.
        group = Pmw.Group(frame3, tag_text = 'Level')
        group.pack(fill = 'both', expand = 1, padx = 15, pady = 10)

	v2 = IntVar()
	v2.set("13") # initialize
        rb11 = Radiobutton(group.interior(), text = 'Grad', variable=v2, value=11)
        rb11.grid(row = 0, column = 0)
        rb12 = Radiobutton(group.interior(), text = 'UnderGrad', variable=v2, value=12)
        rb12.grid(row = 0, column = 1)
        rb13 = Radiobutton(group.interior(), text = 'BOTH', variable=v2, value=13)
        rb13.grid(row = 0, column = 2)


############      Frame 4     ##########################################################


#################        Add Combobox         ##################


        add = [' ', 'Course', 'Instructor', 'Room', 'Time', 'Record']
	dropdown10 = Pmw.ComboBox(frame4,
                label_text = 'ADD    ',
	        labelpos = 'w',
		entry_width=4,
		listheight = 150,
#		buttonaspect = 2.0,
                #selectioncommand = self.changeColour,
		scrolledlist_items = add,
        )
#	dropdown1.grid(row=1)
        dropdown10.pack(pady=5)

	# Display the first colour.
	first = add[0]
	dropdown10.selectitem(first)
	#self.changeText(first)


################     Modify ComboBox In frame 4     ####################


	# Create and pack the dropdown ComboBox.
        modify = [' ', 'Course', 'Instructor', 'Room', 'Time', 'Record']
	dropdown11 = Pmw.ComboBox(frame4,
                label_text = 'MODIFY',
	        labelpos = 'w',
                #selectioncommand = self.changeColour,
		scrolledlist_items = modify,
        )
#	dropdown2.grid(row=2)
	dropdown11.pack(pady=5)
	# Display the first colour.
	first = modify[0]
	dropdown11.selectitem(first)
	#self.changeColour(first)


################      Delete  Combobox  in frame 4  ######################


	# Create and pack the dropdown ComboBox.
        delete = [' ', 'Course', 'Instructor', 'Room', 'Time', 'Record']
	dropdown12 = Pmw.ComboBox(frame4,
                label_text = 'DELETE',
	        labelpos = 'w',
                #selectioncommand = self.changeColour,
		scrolledlist_items = delete,
        )
	#dropdown12.component(delete).configure(width = 4)
#	dropdown2.grid(row=2)
	dropdown12.pack()
	# Display the first colour.
	first = delete[0]
	dropdown12.selectitem(first)
	#self.changeColour(first)


####################    Ok,help,quit  buttons  in farme 4   #######################

	# Create and pack the ButtonBox.
	self.buttonBox = Pmw.ButtonBox(frame4,
		labelpos = 'E',
#		label_text = 'ButtonBox:',
                frame_borderwidth = 2,
                frame_relief = 'groove')
	self.buttonBox.pack(fill = 'both', expand = 1, padx = 15, pady = 15)

	# Add some buttons to the ButtonBox.
	self.buttonBox.add('OK')#, command = self.ok)
	self.buttonBox.add('HELP')#, command = self.apply)
	self.buttonBox.add('QUIT')#, command = self.cancel)

	# Set the default button (the one executed when <Return> is hit).
	self.buttonBox.setdefault('OK')
#	frame4.bind('<Return>', self._processReturnKey)
	frame4.focus_set()

	# Make all the buttons the same width.
	self.buttonBox.alignbuttons()



################## writing days on canvas  in frame1    ########################

       def drawDays(self):
     # Make a list of days of the week

        enumDays=['Mon', 'Tue', 'Wed', 'Thu', 'Fri']

     # Draw text for each of the days

	xpos=20
	ypos=65
	ydiff=80
	for day in enumDays:
	        self.days.create_text(xpos, ypos, text=day, font=("arial", 12, "bold"))
	        ypos=ypos+ydiff


###################       Drawing Time on canvas in frame 1   ##########################################


       def drawTime(self):
     # Make a list of days of the week
        enumTime=['8.00a', '9.00a', '10.00a', '11.00a', '12.00n', '1.00p', '2.00p', '3.00p','4.00p','5.00p','6.00p','7.00p','8.00p']

     	xpos=68
	ypos=15
	xdiff=54
	for time in enumTime:
	        self.time.create_text(xpos, ypos, text=time, font=("arial", 12, "bold"))
	        xpos=xpos+xdiff

	self.time.grid(row=0, column=1)



##############    List of other canvases in frame 1    ###########################################


     # Make a list of days of the week
       def drawCanvas(self):
        CanvasNameList=['MonCanvas', 'TueCanvas', 'WedCanvas', 'ThuCanvas', 'FriCanvas']
     	xpos=68
	ypos=15
	xdiff=54
	for canvas in CanvasNameList:
		self.canvas=Pmw.ScrolledCanvas(frame1,
		borderframe = 1,
		labelpos = 'wn',
		usehullsize = 5,
		hull_width = 800,
		hull_height = 80,
        	)
		i=1
		self.canvas.grid(frame1,row=1, column=i)
		i=i+1
        	self.canvas.resizescrollregion()
 		self.canvas.configure(hscrollmode = 'dynamic')
		self.canvas.configure(vscrollmode = 'static')	                	


#########################################################################################



      	
root = Tk()
app=Schedule(root)
root.mainloop()







More information about the Python-list mailing list