#🔒 Tkinter Error
100 messages · Page 1 of 1 (latest)
@plucky vessel
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import tkinter as tk
def pathname1():
i = bouton1.winfo_id()
print("identité", i)
u = racine.winfo_pathname(i, False)
print("pathname", u)
def pathname2():
i = bouton2.winfo_id()
print("identité", i)
u = racine.winfo_pathname(i, False)
print("pathname", u)
racine = tk.Tk()
racine.geometry("300x300+500+500")
racine.pack_propagate(0)
racine.title("racine")
label = tk.Label(master=racine, text="The mystery of th golden IP")
label.pack()
bouton1 = tk.Button(master=racine, text="name=bouton1", command=pathname1, name="bouton1")
bouton1.pack()
toplevel = tk.Toplevel(master=racine, name="fenetre2", bg="black")
toplevel.geometry("200x200+500+850")
toplevel.grid_propagate(0)
toplevel.title("toplevel")
cadre = tk.Frame(toplevel, width=150, height=150, bg="red")
cadre.pack()
bouton2 = tk.Button(master=toplevel, text="name=bouton2", command=pathname2 ,name="bouton2")
bouton2.pack()
racine.mainloop()``` why i have an error when i click on the button ?
can you give more details?
It works on my local machine
pathname .bouton1
identité 1379062
pathname .bouton1
identité 1379062
pathname .bouton1
identité 1379062
pathname .bouton1
identité 1379062
pathname .bouton1
identité 1379062
pathname .bouton1
identité 1379062
pathname .bouton1
identité 2361440
pathname .fenetre2.bouton2
identité 2361440
pathname .fenetre2.bouton2
identité 2361440
pathname .fenetre2.bouton2
identité 2361440
pathname .fenetre2.bouton2
identité 1379062
pathname .bouton1```
ok
did it work?
can you show the command prompt while you are running it
I only see the dc
ok i gonna use obs
you can use the snipping tools video function
even in admin it doesn't work
in my desktop
this is not a problem in itself I don't think I will use this functionality of tkinter but I am afraid that this problem will appear in other more important circumstances
can you try the following code? I tried to make the variables global and if it doesnt work, we will be able to see the logs.
import tkinter as tk
bouton1_id = None
bouton2_id = None
def pathname1():
global bouton1_id
print(f"id{bouton1_id}")
i = bouton1_id
print("identité", i)
u = racine.winfo_pathname(i, False)
print("pathname", u)
def pathname2():
global bouton2_id
print(f"id{bouton2_id}")
i = bouton2_id
print("identité", i)
u = racine.winfo_pathname(i, False)
print("pathname", u)
racine = tk.Tk()
racine.geometry("300x300+500+500")
racine.pack_propagate(0)
racine.title("racine")
label = tk.Label(master=racine, text="The mystery of th golden IP")
label.pack()
bouton1 = tk.Button(master=racine, text="name=bouton1", command=pathname1, name="bouton1")
bouton1.pack()
bouton1_id = bouton1.winfo_id()
toplevel = tk.Toplevel(master=racine, name="fenetre2", bg="black")
toplevel.geometry("200x200+500+850")
toplevel.grid_propagate(0)
toplevel.title("toplevel")
cadre = tk.Frame(toplevel, width=150, height=150, bg="red")
cadre.pack()
bouton2 = tk.Button(master=toplevel, text="name=bouton2", command=pathname2 ,name="bouton2")
bouton2.pack()
bouton2_id = bouton2.winfo_id()
racine.mainloop()
it doesnt work
can you show what it printed?
id395084
identité 395084
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ytsky\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py", line 1948, in call
return self.func(*args)
^^^^^^^^^^^^^^^^
File "c:\Users\ytsky\Livre tkinter.py", line 11, in pathname1
u = racine.winfo_pathname(i, False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ytsky\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py", line 1186, in winfo_pathname
return self.tk.call(args)
^^^^^^^^^^^^^^^^^^
_tkinter.TclError: window id "395084" doesn't exist in this application
can you add this line right after button1.pack?
print(f"test {bouton1.winfo_id()}")
ok
It is likely due to button not being created on your local machine
PS C:\Users\ytsky> & C:/Users/ytsky/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/ytsky/Livre tkinter.py"
test 1704416
id1704416
identité 1704416
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ytsky\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py", line 1948, in call
return self.func(*args)
^^^^^^^^^^^^^^^^
File "c:\Users\ytsky\Livre tkinter.py", line 11, in pathname1
u = racine.winfo_pathname(i, False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ytsky\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py", line 1186, in winfo_pathname
return self.tk.call(args)
^^^^^^^^^^^^^^^^^^
_tkinter.TclError: window id "1704416" doesn't exist in this application
What does that mean
So probably there is something like a version problem
Just to be sure, does this happen after you click the button, or when you run the code?
after i click
So the window destroys itself after you click
do you have an antivirus of some sort
yes
is it anything other than windows firewall and if it is, can you try running it while it is temporarily off?
can u try updating tkiner by using "pip install --upgrade tk"
I just updated tkinter and it still doesn't work
import tkinter as tk
bouton1_id = None
bouton2_id = None
def pathname1():
i = bouton1_id
print("identité", i)
u = racine.winfo_pathname(i)
print("pathname", u)
def pathname2():
i = bouton2_id
print("identité", i)
u = racine.winfo_pathname(i)
print("pathname", u)
racine = tk.Tk()
racine.geometry("300x300+500+500")
racine.pack_propagate(0)
racine.title("racine")
label = tk.Label(master=racine, text="The mystery of th golden IP")
label.pack()
bouton1 = tk.Button(master=racine, text="name=bouton1", command=pathname1, name="bouton1")
bouton1.pack()
bouton1_id = bouton1.winfo_id()
print(id(bouton1_id))
toplevel = tk.Toplevel(master=racine, name="fenetre2", bg="black")
toplevel.geometry("200x200+500+850")
toplevel.grid_propagate(0)
toplevel.title("toplevel")
cadre = tk.Frame(toplevel, width=150, height=150, bg="red")
cadre.pack()
bouton2 = tk.Button(master=toplevel, text="name=bouton2", command=pathname2 ,name="bouton2")
bouton2.pack()
bouton2_id = bouton2.winfo_id()
racine.mainloop()
I think I figured it out
it doesn't work 😦
well
but when i replace from "u" to the last ")" in: def pathname2():
i = bouton2_id
print("identité", i)
u = racine.winfo_pathname(i)
print("pathname", u)
by
i = bouton2_id
print("identité", i)
like that: def pathname2():
i = bouton2_id
print("identité", i)
i = bouton2_id
print("identité", i)
i can click on button as many times as I want it work
the problem is caused by "racine.winfo_pathname(i)" if you are wondering
so the problem come maybe from winfo_pathname
i think too
8.6
is it just 8.6?
yes
can you try "pip install tk==8.6.13"
ERROR: Could not find a version that satisfies the requirement tk==8.6.13 (from versions: 0.1.0)
ERROR: No matching distribution found for tk==8.6.13
can you
"pip uninstall tkinter"
"pip install tkinter"
that would solve the problem but it is really overkill
can u try "pip show tk-tools"
WARNING: Package(s) not found: tk-tools
"pip install tk-tools"
I just uninstalled then reinstalled python and I am now in 6.13 (tkinter version)
can you try "pip install tk-tools" and re run thje code
its workeeedddd
test 1574510
identité 1574510
pathname .bouton1
thx for your help it's very kind 🙂
have a very good day 😁
you too
bye
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
🔒 Tkinter Error