I've just taken a beginners project from Vegaseat and modified it to fit with a Tkinter tutorial.

I'm just trying to get a Tk window that has a "Go!" button and by pressing it prints the sentence.

I'm having lots of trouble. I've gained a lot from this though, so thanks mounds to Vegaseat

# sentence generator 

import random
from Tkinter import *

# Tkinter is used to make the button
class App:
	def __init__(self, master):
		frame = Frame(master)
		sentence.button = Button(frame, text="Go!", command=sentence.makeSentence)

	def makeSentence(part1, part2, part3, n=1):
		"""return n random sentences"""
		#convert to lists
		p1 = part1.split('\n')
		p2 = part2.split('\n')
		p3 = part3.split('\n')
		#shuffle the lists
		#concatinate the sentences
		sentence = []
		for k in range(n):
				s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
				s = s.capitalize() + '.'
			except IndexError:
		return sentence
# break a typical sentence into 3 parts
# first part of a sentence (subject)
part1 = """\
A panda
Gary Busey"""

# (action)
part2 = """\

# (object)
part3 = """\

sentence = makeSentence(part1, part2, part3)
for item in sentence:
	print item
root = Tk()

app = App(root)


Anyone have a fix for this code? judging by my errors that the Terminal window show upon running I have problems with the <module> sentence = makeSentence(part1, part2, part3) towards the end. Thanks in advance

I attach a slightly corrected program

Definitely better, but I'm still getting the same undefined error.

Strange, it works very well here. Could you post the full Exception traceback ?

makeSentence is a function of the class App. It should be called as such App.makeSentence

The file I attached has only 68 lines. No error can occur on line 122 ! And I commented out the line sentence = ... . So you must have done something to my file. Try to reload it :)

#sentence = makeSentence(part1, part2, part3)
#for item in sentence:
#		print item

That is what I got wrong. Didn't know about the pound signs and that they go there... Thanks guys