Python Forum
[Tkinter] bad window path name - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] bad window path name (/thread-27852.html)



bad window path name - jdos - Jun-24-2020

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)



RE: bad window path name - menator01 - Jun-24-2020

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()



RE: bad window path name - jdos - Jun-25-2020

For me this is what I get




RE: bad window path name - menator01 - Jun-25-2020

The error appears to be coming from the window you're opening. It shows button3. You might want to check that.


RE: bad window path name - jdos - Jun-25-2020

(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.


RE: bad window path name - Yoriz - Jun-25-2020

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)



RE: bad window path name - jdos - Jun-25-2020

(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!