Reputation: 17
I noticed if I eliminate/comment the ########### Create Dropdown list for Code corresponding name ########### section below, the window appears. Also, if I use the same code in a different file, the DropDown list appears as normal.... super weird!! Not sure what is going on here. Can you help? Code below:
from tkinter import *
########### Create main window, call it root ###########
root = Tk()
#Defining classes and methods
class Code:
def __init__(self, code, name, skill, description):
self.code = code
self.name = name
self.skill = skill
self.description = description
codesList.append(self)
namesList.append(name)
#Defining variables
codesList = []
namesList = []
selectedname = StringVar()
selectedname.set('Please select the correct the correct knowledge category necessary to resolve the ticket.')
A11 = Code(11, 'Fundamentals', 'A', '')
B11 = Code(11,'Geology', 'B', '')
B12 = Code(12,'Reservoir Engineering', 'B', '')
########### Create list of Dictionaries ###########
TypeD = {}
SiteD = {}
P4dcD = {}
SkillD = {}
########### Create Incident Types Dictionary###########
TypeD = dict(Normal='NORMAL', \
Parent='PARENT', \
Child='CHILD')
TypeNameL = list()
for i in TypeD.keys():
TypeNameL.append(i)
########### Create Skill Levels ###########
SkillD = dict(Awareness = 'A', \
Foundation = 'B', \
Skill = 'C', \
Advance = 'D')
SkillNameL = list()
for i in SkillD.keys():
SkillNameL.append(i)
########### Create main menu ###########
mainmenu = Menu(root)
root.config(menu = mainmenu)
submenu = Menu(mainmenu)
mainmenu.add_cascade(label = "File", menu=submenu)
submenu.add_command(label = "New Project", command=doNothing)
submenu.add_separator()
submenu.add_command(label = "Exit", command= exitmeth)
editmenu = Menu(mainmenu)
mainmenu.add_cascade(label = "Edit", menu=editmenu)
editmenu.add_command(label = "Redo", command = doNothing)
########### Toolbar ###########
toolbar = Frame(root, bg="blue")
insertButt = Button(toolbar, text = "Insert image", command = InsertImgcmd)
insertButt.pack(side=LEFT, padx = 2, pady=2)
printButt = Button(toolbar, text="Print", command = printP4dcD)
printButt.pack(side=LEFT, padx = 2, pady=2)
toolbar.pack(side=TOP, fill=X)
########### Create Dropdown list for Code corresponding name ###########
LabelCodeDDL = Label(root, text="Petrel Code").grid(row=2, column=0, sticky=W)
CodeDDL = OptionMenu(root, selectedname, *namesList)
CodeDDL.pack()
CodeDDL.configure(font=("Calibri", 11))
CodeDDL.grid(row=3, column=0)
########## Statusbar ##########
statusbar = Label(root, text='', bd=1, relief=SUNKEN, anchor=W)
statusbar.pack(side=BOTTOM, fill=X)
root.title("Ticket Summary Tool")
root.geometry("300x200")
root.mainloop()
I should get some errors or the window should display. I can't figure out what is happening...
Upvotes: 0
Views: 53
Reputation: 386332
You are using both pack
and grid
with widgets that are directly in root
(for example, LabelCodeDDL = Label(root, text="Petrel Code").grid(row=2, column=0, sticky=W)
and toolbar.pack(side=TOP, fill=X)
). You cannot mix them like that. All widgets that have the same parent or master must use one or the other.
Upvotes: 1