Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_tkinter.TclError: can't find package Thread #1

Closed
pobv opened this issue Aug 27, 2019 · 4 comments
Closed

_tkinter.TclError: can't find package Thread #1

pobv opened this issue Aug 27, 2019 · 4 comments

Comments

@pobv
Copy link

pobv commented Aug 27, 2019

I assume your package would help me a lot, as I try to find/emulate something like an "invokeLater" or "runOnUIThread" for Tkinter in python3 that works on both pypy and cpython (best - that works on any implementation). After installation on pypy3.6.7.1.1 (installation itself worked) I got

$ pypy y.py
Traceback (most recent call last):
  File "y.py", line 4, in <module>
    tkt = TkThread(root)  # make the thread-safe callable
  File "/opt/pypy3.6-7.1.1-beta-linux_x86_64-portable/site-packages/tkthread/__init__.py", line 120, in __init__
    self.root.eval('package require Thread')
  File "/opt/pypy3.6-7.1.1-beta-linux_x86_64-portable/lib_pypy/_tkinter/app.py", line 344, in eval
    self.raiseTclError()
  File "/opt/pypy3.6-7.1.1-beta-linux_x86_64-portable/lib_pypy/_tkinter/app.py", line 168, in raiseTclError
    tklib.Tcl_GetStringResult(self.interp)).decode('utf-8'))
_tkinter.TclError: can't find package Thread

where y.py is the sample on this packages homepage.

from tkthread import tk, TkThread

root = tk.Tk()        # create the root window
tkt = TkThread(root)  # make the thread-safe callable

import threading, time
def run(func):
    threading.Thread(target=func).start()

run(lambda:     root.wm_title('FAILURE'))
run(lambda: tkt(root.wm_title,'SUCCESS'))

root.update()
time.sleep(2)  # _tkinter.c:WaitForMainloop fails
root.mainloop()

I am on Ubuntu 18.04 and have tk-dev installed

 $ dpkg -l | grep tk8
ii  libtk8.6:amd64                         8.6.8-4                                amd64        Tk toolkit for Tcl and X11 v8.6 - run-time files
ii  tk8.6                                  8.6.8-4                                amd64        Tk toolkit for Tcl and X11 v8.6 - windowing shell
ii  tk8.6-blt2.5                           2.5.3+dfsg-4                           amd64        graphics extension library for Tcl/Tk - library
ii  tk8.6-dev:amd64                        8.6.8-4                                amd64        Tk toolkit for Tcl and X11 v8.6 - development files
$ uname -a
Linux x220t 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"

Any help appreciated.

@serwy
Copy link
Owner

serwy commented Aug 29, 2019

Try installing the tcl-thread package. I ran into this same issue on Raspbian.

@pobv
Copy link
Author

pobv commented Aug 29, 2019

Thanks a lot.
apt-get install tcl-thread
did the trick for python3 (I was only searching for tk, not tcl). And the packages works beautifully with python3, there is almost no delay when updating from a background thread, nice! Exactly what I was looking for, an implementation of runOnUiThread or invokeLater or however it is called in other GUI frameworks.

However, I do not know how to proceed for pypy (where the package is really needed!) and i don't know anything about tcl. I have seen that tcl-thread install also /usr/lib/tcltk/x86_64-linux-gnu/thread2.8.2/libthread2.8.2.so in addition to some tcl files and apparently pypy has its own tcl/tk and still complains about a missing Thread package.

If that works it should really become part of the standard library...

@pobv
Copy link
Author

pobv commented Aug 29, 2019

ok, i just blindly copied the entire installation directory of tcl-thread into the pypy installation and that worked.
cp -rp /usr/lib/tcltk/x86_64-linux-gnu/thread2.8.2 /opt/pypy3.6-7.1.1-beta-linux_x86_64-portable/lib/tcl/
Might not be clean, but I don't complain. It works as smoothly and fast under pypy as under python3.

Having tkt in the standard (or call it invoke_later or whatever) would make tkinter much more usable for all people that do know other UI frameworks and threading. Thanks for the package.

@pobv pobv closed this as completed Aug 29, 2019
@Jakar510
Copy link

Is there a way to get this working on Windows 10, as it is in Linux shown above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants