Python Forum
[Tkinter] bad window path name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] bad window path name
#1
Hey guys, I have a couple of python programs with GUI that work as should, now I have created another program that loads the other programs and runs them, think of it as a selector.
All programs are in the same folder.
The issue is that when I press the button and start one of the programs, when the called program loads I get the error:
Error:
return self.tk.getint(self.tk.call( _tkinter.TclError: bad window path name ".!button"
This is the code for the caller program.

root=tk.Tk()
root.title('Program Selection')
canvas1=tk.Canvas(root,width =300, height=150)
canvas1.pack()


def prog():
    import prog1_v1
    return

def prog2():
    import prog2_v1
    return

labelTop=tk.Label(canvas1,text='Choose a program')
canvas1.create_window(150,40,window=labelTop)

button1=tk.Button(text='program1',command = prog)
canvas1.create_window(150,75,window=button1)

button2=tk.Button(text='program2',command=prog2)
canvas1.create_window(150,110,window=button2)
Reply
#2
This works for me

#! /usr/bin/env python3
import tkinter as tk

root=tk.Tk()
root.title('Program Selection')
canvas1=tk.Canvas(root,width =300, height=150)
canvas1.pack()


def prog():
    import play
    return

def prog2():
    import game
    return

labelTop=tk.Label(canvas1,text='Choose a program')
canvas1.create_window(150,40,window=labelTop)

button1=tk.Button(text='program1',command = prog)
canvas1.create_window(150,75,window=button1)

button2=tk.Button(text='program2',command=prog2)
canvas1.create_window(150,110,window=button2)

root.mainloop()

Reply
#3
For me this is what I get

Reply
#4
The error appears to be coming from the window you're opening. It shows button3. You might want to check that.
Reply
#5
(Jun-25-2020, 06:10 AM)menator01 Wrote: The error appears to be coming from the window you're opening. It shows button3. You might want to check that.

I know as I said in the first post, the called program (say program1) works correctly without any errors though it takes some time to load when started on its own. The issue is when I try to load it via the loader program it is then that the error occurs.
If you check the video you can see that.
Reply
#6
When you define the label you have given a parent attribute of canvas1
labelTop=tk.Label(canvas1,text='Choose a program')
but your buttons have no parent
button1=tk.Button(text='program1',command = prog)
button2=tk.Button(text='program2',command=prog2)
Reply
#7
(Jun-25-2020, 06:21 AM)Yoriz Wrote: When you define the label you have given a parent attribute of canvas1
labelTop=tk.Label(canvas1,text='Choose a program')
but your buttons have no parent
button1=tk.Button(text='program1',command = prog)
button2=tk.Button(text='program2',command=prog2)

Thanks mate I didn't think of that as it seemed to work just fine without the parent. Now it's working as it should!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter.TclError: bad window path name kenwatts275 3 1,596 Apr-26-2020, 08:16 PM
Last Post: kenwatts275
  tkinter window and turtle window error 1885 3 1,629 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 4,212 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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