#🔒 Tkinter Error

100 messages · Page 1 of 1 (latest)

fossil spadeBOT
#

@plucky vessel

Python help channel opened

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.

plucky vessel
#
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 ?
scarlet wedge
#

It works on my local machine

plucky vessel
#

oh..

#

ok wait

scarlet wedge
#
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```
plucky vessel
#

oh we don't see on my record but the error spawn when i click on the button

scarlet wedge
#

can you try running it on your windows base environment?

plucky vessel
#

ok

scarlet wedge
plucky vessel
#

nop

#

lol we don't see

#

but i have the same problem

scarlet wedge
#

I only see the dc

plucky vessel
#

ok i gonna use obs

scarlet wedge
plucky vessel
#

oh yes

scarlet wedge
#

can you run it on cmd as an administrator?

#

there is no problem in your code

plucky vessel
#

even in admin it doesn't work

scarlet wedge
#

I see

#

what folder do you keep the code

plucky vessel
#

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

scarlet wedge
#

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()
plucky vessel
#

it doesnt work

scarlet wedge
#

can you show what it printed?

plucky vessel
#

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

scarlet wedge
#

can you add this line right after button1.pack?

print(f"test {bouton1.winfo_id()}")
plucky vessel
#

ok

scarlet wedge
#

It is likely due to button not being created on your local machine

plucky vessel
#

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

plucky vessel
scarlet wedge
#

Just to be sure, does this happen after you click the button, or when you run the code?

plucky vessel
#

after i click

scarlet wedge
#

So the window destroys itself after you click

#

do you have an antivirus of some sort

plucky vessel
#

yes

scarlet wedge
#

is it anything other than windows firewall and if it is, can you try running it while it is temporarily off?

plucky vessel
#

i gonna try

#

no it doesn't work

scarlet wedge
#

can u try updating tkiner by using "pip install --upgrade tk"

plucky vessel
#

I just updated tkinter and it still doesn't work

scarlet wedge
#
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

plucky vessel
#

it doesn't work 😦

scarlet wedge
#

well

plucky vessel
#

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

scarlet wedge
#

the problem is caused by "racine.winfo_pathname(i)" if you are wondering

plucky vessel
#

so the problem come maybe from winfo_pathname

scarlet wedge
#

can you use "python -m tkinter -V" on cmd

#

and tell the version of you r tkiner?

plucky vessel
#

8.6

scarlet wedge
#

is it just 8.6?

plucky vessel
#

yes

scarlet wedge
#

can you try "pip install tk==8.6.13"

plucky vessel
#

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

scarlet wedge
#

can you
"pip uninstall tkinter"
"pip install tkinter"

plucky vessel
#

yes

#

WARNING: Skipping tkinter as it is not installed.

#

What does that mean

scarlet wedge
#

oh sorry

#

"pip uninstall tk"
"pip install tk"

plucky vessel
#

ok

#

again 8.6

#

maybe unistall python?

scarlet wedge
#

that would solve the problem but it is really overkill

#

can u try "pip show tk-tools"

plucky vessel
#

WARNING: Package(s) not found: tk-tools

scarlet wedge
#

"pip install tk-tools"

plucky vessel
#

I just uninstalled then reinstalled python and I am now in 6.13 (tkinter version)

scarlet wedge
#

can you try "pip install tk-tools" and re run thje code

plucky vessel
#

its workeeedddd

plucky vessel
#

test 1574510
identité 1574510
pathname .bouton1

plucky vessel
scarlet wedge
#

👍

plucky vessel
scarlet wedge
#

you too

plucky vessel
#

thx 🙂

#

bye

scarlet wedge
#

bye

fossil spadeBOT
#
Python help channel closed

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