Only using grid Tkinter but still getting TclError

  geometry, label, python, tkinter

So I just started using Google Colab and I keep getting this error:
TclError: cannot use geometry manager grid inside . which already has slaves managed by pack

I’m trying to make a GUI window that takes in the information from the user and saves it.

Everything I’ve read online says that the issue is that I’m using pack() and grid(), but I’m only using grid. The error starts when I first try to place my labels (sourceLabel).

I’m so confused, any help would be great.

try:                        # In order to be able to import tkinter for
    import tkinter as tk    # either in python 2 or in python 3
    from tkinter import *
except ImportError:
    import Tkinter as tk
    from Tkinter import *

#creates window
window = tk.Tk()
window.title("File Information")

window.rowconfigure([0,1], minsize=30)
window.columnconfigure([0, 1, 2, 3], minsize=30)


#this program opens the file with information and adds the new information to it
def saveInfo():
    value = path.get()
    loc = source.get()
    recode = recoding.get()
    #change name of file and will this make them see everything
    #f = open("./info.txt", "a+")
    #f.write("Source Data File Location: " + loc + ", Complete File Path: " + value + ", Is recoding of column names and/or values desired?: " + recode)
    #f.flush() 
    #f.seek(0)
    #content = f.read()
    #print (content)
    finalList = [value,loc,recode]
    #f.close()
    window.withdraw()
    print (finalList)
    return finalList



#creates a text label, fg=foreground and bg=background, theyre the locations of colors, width and height are measured by text units which are separate horizonatal and vertical
sourceLabel = tk.Label(
  text="Source Data File Location:",
  width = 21,
  height=2)
#adds text to window
sourceLabel.grid(row=0,column=0)

#creates second label
pathLabel = tk.Label(
  text="Complete File Path:",
  width = 20,
  height=2)
#adds text to window
pathLabel.grid(row=1,column=0)

#creates third label
sourceLabel = tk.Label(
  text="Is recoding of column n names and/or values n desired:",
  width = 20,
  height=4)
#adds text to window
sourceLabel.grid(row=2,column=0)

#create dropdown for sources
source = StringVar(window)
source.set("Local") # default value
sourceOption = OptionMenu(window, source, "Local", "Google Drive", "One Drive")
sourceOption.grid(row=0,column=1,sticky="ew")

#adds path entry
path = tk.Entry(fg="black", bg="white", width=35)
#adds path to window
path.grid(row=1,column=1,sticky="ew")

#create dropdown for recoding
recoding = StringVar(window)
recoding.set("Yes") # default value
recodingOption = OptionMenu(window, recoding, "Yes", "No")
recodingOption.grid(row=2,column=1,sticky="new")
      
#creates the click to save button
button = tk.Button(
    text="Click to Save",
    width=10,
    height=1,
    bg="white",
    fg="black", command=saveInfo
)

#adds Button to window 
button.grid(row=4,column=1,sticky="w")


#runs window
window.mainloop()
window.destroy()

Source: Python Questions

LEAVE A COMMENT