Hi,
I'm very new to Python, sort of following Dive into Python 2 and wanted to dabble with some Tkinter programming. I've tried to make a little program that takes 3 sets of words and makes combinations of each word in the 3 sets to make keywords for websites. When I run the script, the GUI appears as expected, but I get the following error when I click on the Create Combinations button
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "combomaker.py", line 34, in makeCombinations
primaryraw = primaryKeyWordsBox.get()
AttributeError: 'NoneType' object has no attribute 'get'
The code I'm trying to fix
#!/usr/bin/env python
from Tkinter import *
primaryKeyWordsLabel = None
primaryKeyWordsBox = None
secondaryKeyWordsLabel = None
secondaryKeyWordsBox = None
tertiaryKeyWordsLabel = None
tertiaryKeyWordsBox = None
class Application(Frame):
def __init__(self, master=None, padx = 10, pady= 10):
Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.primaryKeyWordsLabel = LabelFrame(text="Primary Key Words", padx=10, pady=10)
self.primaryKeyWordsLabel.grid()
self.primaryKeyWordsBox = Text(primaryKeyWordsLabel, autoseparators=True, height=5, undo=True)
self.primaryKeyWordsBox.grid()
self.secondaryKeyWordsLabel = LabelFrame(text="Secondary Key Words", padx=10, pady=10)
self.secondaryKeyWordsLabel.grid()
self.secondaryKeyWordsBox = Text(secondaryKeyWordsLabel, autoseparators=True, height=5, undo=True)
self.secondaryKeyWordsBox.grid()
self.tertiaryKeyWordsLabel = LabelFrame(text="Tertiary Key Words", padx=10, pady=10)
self.tertiaryKeyWordsLabel.grid()
self.tertiaryKeyWordsBox = Text(tertiaryKeyWordsLabel, autoseparators=True, height=5, undo=True)
self.tertiaryKeyWordsBox.grid()
self.goButton = Button(text="Create Combinations", command=makeCombinations)
self.goButton.grid()
def makeCombinations():
primaryraw = primaryKeyWordsBox.get()
primary = primaryraw.split(', ')
secondaryraw = secondaryKeyWordsBox.get()
secondary = secondaryraw.split(', ')
tertiaryraw = tertiaryKeyWordsBox.get()
tertiary = tertiaryraw.split(', ')
output=[]
filename = "output.txt"
for i in range(len(primary)):
for j in range(len(secondary)):
for k in range(len(tertiary)):
rawcombo=str(primary[i])+" "+str(secondary[j])+" "+str(tertiary[k])
output.append(rawcombo)
FILE = open(filename, w)
for combo in output:
FILE.write(combo+",\n")
FILE.close()
app = Application()
app.master.title("Keyword Generator")
app.mainloop()
I may have thrown myself into GUI programming too fast, this is my first attempt at any GUI work but not my first time programming.
Many thanks in advance :)