Jan-30-2020, 09:37 PM
Main/Root Window
My issue is in the TopLevel/Secondary Window. In that class, I have a ListBox which I can declare successfully and will appear, but my end goal is to have a button on that screen call a secondary function which will then populate the Listbox with some data from a DB.
Before tackling the database logic I tried to simply just put some data in manually using the below method:
AttributeError: 'NoneType' object has no attribute 'insert'
Any help would be appreciated :)
My issue is in the TopLevel/Secondary Window. In that class, I have a ListBox which I can declare successfully and will appear, but my end goal is to have a button on that screen call a secondary function which will then populate the Listbox with some data from a DB.
Before tackling the database logic I tried to simply just put some data in manually using the below method:
self.Lb1.insert(END, "Entry Value")But for some reason, it doesn't recognize that command which results in the following error
AttributeError: 'NoneType' object has no attribute 'insert'
Any help would be appreciated :)
from tkinter import *
from tkinter import ttk
class Application(object):
def __init__(self, master):
self.topColor = '#f2f2f2'
self.bottomColor = '#e6e6e6'
self.master = master
# Configure our menu
menu = Menu(self.master)
self.master.config(menu = menu)
file = Menu(menu, tearoff = 0)
file.add_command(label = 'About', command = self.aboutMessage)
file.add_command(label = 'Exit', command = self.client_exit)
menu.add_cascade(label = 'File', menu = file)
edit = Menu(menu, tearoff = 0)
edit.add_command(label = 'Undo')
menu.add_cascade(label = 'Edit', menu = edit)
rules = Menu(menu, tearoff = 0)
rules.add_command(label = 'Add Table & Function', command = self.addFuncTable)
rules.add_command(label = 'Search', command = self.search)
menu.add_cascade(label = 'Rules', menu = rules)
# ---- Top Frame ---- #
# Configure frames
self.top = Frame(master, height = 71, bg = self.topColor)
self.top.pack(fill = X)
self.bottom = Frame(master, height = 530, bg = self.bottomColor)
self.bottom.pack(fill = X)
self.top_image = PhotoImage(file ='Images/Logo.png')
Label(self.top, image = self.top_image).place(x = -1, y = -1)
Label(self.top, text = "H03 & HF9 Mosaic Script Generation Tool", bg = self.topColor, font = ('Calbri', 11)).place(x = 70, y = 5)
Label(self.top, text = 'Use the below entry boxes to fill in the necessary information about your ITR', bg = self.topColor).place(x = 70, y = 30)
Label(self.top, text = 'This will include your Version Number(s), GUID, etc', bg = self.topColor).place(x = 70, y = 48)
# ---- Bottom Frame ---- #
# Define var's for each of our fields so we can get the value
self.entry_appendixPath = StringVar()
self.entry_rateSheetPath = StringVar()
Label(self.bottom, text = 'File Path for Appendix:', bg = self.bottomColor).place(x = 4, y = 20)
self.appendix = ttk.Entry(self.bottom, width = 30, textvariable = self.entry_appendixPath).place(x = 7, y = 40)
Label(self.bottom, text = "File Path for Rate Sheet:", bg = self.bottomColor).place(x = 250, y = 20)
self.rateSheet = ttk.Entry(self.bottom, width = 30, textvariable = self.entry_rateSheetPath).place(x = 253, y = 40)
Label(self.bottom, text = "Script Author:", bg = self.bottomColor).place(x = 4, y = 80)
ttk.Entry(self.bottom).place(x = 7, y = 100)
Label(self.bottom, text = "GUID Identifier:", bg = self.bottomColor).place(x = 170, y = 80)
ttk.Entry(self.bottom).place(x = 173, y = 100)
self.StateCodeVal = StringVar()
Label(self.bottom, text = "State Code:", bg = self.bottomColor).place(x = 350, y = 80)
ttk.Combobox(self.bottom, textvariable = self.StateCodeVal, width = 10, values = [
"PA", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA",
"HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA",
"MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY",
"NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX",
"UT", "VT", "VA", "WA", "WV", "WI", "WY"
]).place(x = 353, y = 100)
Label(self.bottom, text = "Current Version", bg = self.bottomColor).place(x = 4, y = 135)
ttk.Entry(self.bottom).place(x = 7, y = 155)
Label(self.bottom, text = "New Version:", bg = self.bottomColor).place(x = 170, y = 135)
ttk.Entry(self.bottom).place(x = 173, y = 155)
Label(self.bottom, text = "UW Company:", bg = self.bottomColor).place(x = 350, y = 135)
ttk.Entry(self.bottom, width = 10).place(x = 353, y = 155)
Button(self.bottom, text="Lookup Version", command=self.lookupOldVersion).place(x=6, y=180)
# Not an easy way to execute a stored proc in python with OUTPUT params
# Button(self.bottom, text="Generate").place(x = 173, y = 180)
Label(self.bottom, text="Above button call requires that both State Code and Apex Flag are valued!", bg = self.bottomColor, fg="Red").place(x = 4, y = 210)
self.ApexCheck = StringVar()
Label(self.bottom, text="Apex Flag ( 1 -> is Apex, 0 -> Legacy):",
bg=self.bottomColor).place(x = 4, y = 250)
ttk.Combobox(self.bottom, textvariable=self.ApexCheck, width = 10, values = [
1, 2
]).place(x = 4, y = 272)
Label(self.bottom, text = "Do we need to create new procedure(s) or table(s) for this ITR?", bg = self.bottomColor).place(x = 4, y = 310)
# Set style for ttk.RadioButton since bg= is not supported
s = ttk.Style()
s.configure(
'myStyle.TRadioButton',
background = self.bottomColor
)
self.newCheck = IntVar()
ttk.Radiobutton(self.bottom, text = "Yes", variable = self.newCheck, value = 1).place(x = 5, y = 335)
ttk.Radiobutton(self.bottom, text = "No", variable = self.newCheck, value = 0).place(x = 5, y = 360)
# Radiobutton(self.bottom, text = "Yes", bg = self.bottomColor, variable = newCheck, value = 1).place(x = 4, y = 270)
# Radiobutton(self.bottom, text = "No", bg = self.bottomColor, variable = newCheck, value = 0).place(x = 4, y = 290)
# Checkbutton(self.bottom, bg = self.bottomColor, text = "Yes", variable = newCheck).place(x = 4, y = 270)
Button(self.bottom, text = 'Submit', fg = 'white', bg = '#00802b', command = self.getEntries).place(x = 4 , y = 400)
def search(self):
S = Search.Search()
def main():
root = Tk()
app = Application(root)
root.title('Main Window')
root.geometry('500x600')
root.resizable(False, False)
root.mainloop()
if __name__ == '__main__':
main()Second Window# Tkinter modules
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
class Search(Toplevel):
def __init__(self):
Toplevel.__init__(self)
self.geometry('500x500')
self.title('Search')
self.resizable(False, False)
self.topColor = '#f2f2f2'
self.bottomColor = '#e6e6e6'
# Configure frames
self.top = Frame(self, height=71, bg=self.topColor)
self.top.pack(fill=X)
self.bottom = Frame(self, height=430, bg=self.bottomColor)
self.bottom.pack(fill=X)
self.top_image = PhotoImage(file='Images/Logo.png')
Label(self.top, image=self.top_image).place(x=-1, y=-1)
Label(self.bottom, text="Current Version:", bg=self.bottomColor).place(x = 5, y = 15)
ttk.Entry(self.bottom).place(x = 7, y = 35)
Label(self.bottom, text="New Version:", bg=self.bottomColor).place(x = 150, y = 15)
ttk.Entry(self.bottom).place(x = 153, y = 35)
Button(self.bottom, text = "Get Existing Rules ..").place(x = 5, y = 65)
self.Lb1 = Listbox(self.bottom).place(x = 5, y = 140)
def updateListBox(self):
pass
