Python Forum
tkinter.TclError: bad window path name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter.TclError: bad window path name
#1
Hi all,
I am getting the error _tkinter.TclError: bad window path name ".!toplevel.!frame.!combobox
When I click on the "Columns" button the first time, it opens up a new window no problem.
When I click on the "Exit" button to close out the window and click on the "Columns" button again, I get the bad window error.
It is failing on line 19: column_values[i][j].grid(row=i,column= j)
Below is the code.
Any help would be appreciated.
Thanks in advance.

from tkinter import *
from tkinter import ttk
import tkinter.font as font

def get_columns(field_names):
    new_window = Toplevel(mw)
    new_window.wm_title("Select Columns")
    new_window.geometry('900x500+250+150')

    frame3 = Frame(new_window)
    framebot = Frame(new_window)
    frame3.pack(side=TOP,fill=X)
    framebot.pack(side=BOTTOM,fill=X)

    for i in range(0,max_columns):
      column_values.append([])
      j = 0
      column_values[i].append(ttk.Combobox(frame3,values=field_names))
      column_values[i][j].grid(row=i,column= j)

    exit_button = Button(framebot,text='Exit',font=("Times",16),command=new_window.destroy).pack(side="right")

# Start the main program here
if __name__ == "__main__":
    current_file = __file__
    mw=Tk()
    mw.geometry('900x500+200+150')
    mw.title(current_file)

    frame1 = Frame(mw)
    framebot = Frame(mw)
    frame1.pack(side=TOP,fill=X)
    framebot.pack(side=BOTTOM,fill=X)

    w1 = Label(frame1, text="Database Name: ",font=("Times",16)).pack(side="left")
    dbase = StringVar()
    a1 = ttk.Combobox(frame1,width=40,font=("Times",16),textvar=dbase)
    a1.pack(side="left")

    field_names = ["A.a","B.b","C.c"]
    max_columns = 10
    column_values = []

    btn2 = Button(framebot,text='Columns',font=("Times",16),command=lambda: get_columns(field_names)).pack(side="left")
    btn6 = Button(framebot,text='Exit',font=("Times",16),command=mw.quit).pack(side="right")

    mw.mainloop()
Reply
#2
Please post complete unaltered error traceback. It contains information that is very useful in determining cause of error.
Reply
#3
The problem is caused by you making a new window each time the Columns button is pressed. Though wasteful and potentially confusing, this would work if you also reset the column_values array.

I added some comments below to point out the problem spots.
def get_columns(field_names):
    new_window = Toplevel(mw)
    new_window.wm_title("Select Columns")
    new_window.geometry('900x500+250+150')

    frame3 = Frame(new_window)
    framebot = Frame(new_window)
    frame3.pack(side=TOP,fill=X)
    framebot.pack(side=BOTTOM,fill=X)
 
    for i in range(0,max_columns):
      column_values.append([])  # 2nd time around column_values is not empty
      j = 0
      # 2nd time around column_values[0] holds two combo boxes, one which doesn't exist
      # anymore because you deleted it.
      column_values[i].append(ttk.Combobox(frame3,values=field_names))
      # column_values[0][0] is the deleted combo box
      column_values[i][j].grid(row=i,column= j)
 
    exit_button = Button(framebot,text='Exit',font=("Times",16),command=new_window.destroy).pack(side="right")
Reply
#4
Thanks for your responses. I added "column_values.clear()" before the for loop and that seems to have fixed the problem.
Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function in new window (tkinter) Dale22 2 81 7 hours ago
Last Post: Larz60+
  Scrollable big image in a window (TKinter) Prospekteur 3 256 Sep-14-2020, 03:06 AM
Last Post: Larz60+
  [Tkinter] Python - Tkinter : How can I send path Excel from GUI to scripte johnjh 2 534 Aug-28-2020, 05:38 PM
Last Post: maaad
  Run more than one window together with tkinter SmukasPlays 1 251 Aug-24-2020, 05:00 PM
Last Post: Larz60+
  Adding an image to a tkinter window djwilson0495 2 753 Aug-23-2020, 11:07 AM
Last Post: ebolisa
  [Tkinter] _tkinter.TclError: bitmap "Icon.gif" not defined djwilson0495 2 761 Aug-05-2020, 02:27 PM
Last Post: wuf
  [Tkinter] calling a new window from a tkinter window neuroprogrammer 2 337 Jul-28-2020, 10:59 PM
Last Post: deanhystad
  How to display results from terminal window onto tkinter. buttercup 0 229 Jul-21-2020, 04:41 AM
Last Post: buttercup
  [Tkinter] bad window path name jdos 6 536 Jun-25-2020, 06:25 AM
Last Post: jdos
  [Tkinter] _tkinter.TclError: image "pyimage2" doesn't exist Killdoz 1 1,276 May-30-2020, 09:48 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020