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)
frame.pack()
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
random.shuffle(p1)
random.shuffle(p2)
random.shuffle(p3)
#concatinate the sentences
sentence = []
for k in range(n):
try:
s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
s = s.capitalize() + '.'
sentence.append(s)
except IndexError:
break
return sentence
# break a typical sentence into 3 parts
# first part of a sentence (subject)
part1 = """\
A panda
Gary Busey"""
# (action)
part2 = """\
slaps
eats
gores
"""
# (object)
part3 = """\
puppies
bananas
"""
sentence = makeSentence(part1, part2, part3)
for item in sentence:
print item
root = Tk()
app = App(root)
root.mainloop()
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