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


Messages In This Thread
tkinter.TclError: bad window path name - by kenwatts275 - Apr-25-2020, 08:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 346 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] CTkScrollableDropdown error: bad window path name ".!ctkscrollabledropdown" CopperGenie 1 219 Mar-03-2024, 04:32 AM
Last Post: deanhystad
  [Tkinter] (CLOSED) CTkScrollableDropdown error: bad window path name ".!ctkscrollabledropdown" CopperGenie 4 421 Mar-03-2024, 03:21 AM
Last Post: CopperGenie
  Tkinter multiple windows in the same window tomro91 1 788 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,388 May-25-2023, 07:37 PM
Last Post: deanhystad
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 5,779 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  [Tkinter] tkinter.TclError: expected integer but got " " TWB 2 3,532 Feb-19-2023, 05:11 PM
Last Post: TWB
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,833 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,866 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,547 Feb-17-2022, 07:02 AM
Last Post: pymn

Forum Jump:

User Panel Messages

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