Getting "DEPRECATION WARNING" about Tk
Asked Answered
J

4

8

I am trying to following the answer to this question in an attempt to copy to clipboard however all solutions provided in the answer seem to have failed me. On macOS, I have successfully used pyperclip and subprocess.run to copy to clipboard as described in the linked post, however on centOS neither works. I have also tried using Tkinter on macOS however when I run the following simple code:

  from tkinter import Tk
  r = Tk()

I get the following deprecation warning:

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.

I don't really want to build my application with deprecated dependencies however seeing that centOS doesn't support pyperclip or subprocess.run I feel like I have no other options.

Specifically I would like to know if there exists a good solution to my problem, that is, I want to copy to clipboard on centOS and ideally, I want a solution that will work on "most" platforms. Please note that I am using python3.

Jere answered 19/5, 2020 at 8:56 Comment(8)
Are you using python2-x now?Prostration
No I'm using python3 on both centos and macos. Thanks for pointing out that this wasn't clearly stated, I have updated my question accordinglyJere
In Python3,if you want to import tkinter you need to use import tkinter not import Tkinter.Prostration
Thanks for pointing this out, I have changed my question again. I just ran this and unfortunately I still get the same deprecation warningJere
Maybe you need to update your tkinter.Here is something maybe will help.Prostration
on linux pyperclip uses bash command xclip or xsel so if you have installed xclip or xsel then it should work or you can do the same using even subprocess.run("xclip ...."). But xclip or xsel may need X11 XWindow (the same with tkinter - it needs XWindow/X11)Unbar
BTW: do you really has to use clipboard? Maybe you could save it in file and later read from file? It works on all systems.Unbar
I would like to save a password to clipboard so the user can paste the password into a login without needing to show the password on screen. However, even beyond this particular goal, I feel that there should be a straightforward way to interface with the clipboard on linux. Thanks for recommending xclip and xsel, I'll take a look at theseJere
T
1

You have 2 options:

  1. Ignore the DEPRECATION WARNING: See this post Using tkinter with Catalina, how to avoid deprecation warning? helped me a lot.

  2. Upgrade Python: See the official documentation IDLE and tkinter with Tcl/Tk on macOS

Titicaca answered 9/4, 2022 at 11:24 Comment(0)
E
1

Here is how I resolved this problem for my environment: I am on a Mac Monterey 12

  1. brew install tcl-tk
  2. brew install [email protected]
  3. pyenv install 3.11.4 (uninstall it if you have it already, then reinstall it. This will make the python use the existing version of tk)
  4. pyenv local 3.11.4, now run your python code.
Einsteinium answered 12/11, 2023 at 20:1 Comment(0)
A
0

I can't answer on the original question, because it is deprecated now, but because it is linking to this question, I will post my solution here (which assumes pyenv is installed):

I followed the steps of @Karthik R here https://mcmap.net/q/1049974/-deprecation-warning-the-system-version-of-tk-is-deprecated-m1-mac-in-vs-code-global-python-duplicate but this didn't solve my problem. What I did and worked was based on the following article: https://blog.lanzani.nl/2020/install-tkinter-macos/ which expands @Karthik R's solution approach

Solution (Note: change the pyenv version to your version)

$ brew uninstall tcl-tk
$ pyenv uninstall 3.10.8
$ brew install tcl-tk
$ export PATH="/usr/local/opt/tcl-tk/bin:$PATH"
$ export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
$ export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
$ export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
$ export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'"
$ 
$ pyenv install 3.10.8
$ pyenv global 3.10.8

# Test the installation
$ python -m tkinter

EDIT: this solution was tried out on an Intel-based iMac with macOS Ventura 13.1 installed.

Annecy answered 16/2, 2023 at 10:28 Comment(0)
M
0

Answer also found here: DEPRECATION WARNING: The system version of Tk is deprecated, M1 Mac in Vs Code - global Python


If you have Homebrew installed, you can update tk with:

brew uninstall tcl-tk --devel
brew install tcl-tk

Which is the recommended option

Then you may need to add export PATH="/usr/local/opt/tcl-tk/bin:$PATH" to your .zshrc file:

If you are using a zsh terminal:

Zsh tab

Use:

echo "# For tkinter 
export PATH=\"/usr/local/opt/tcl-tk/bin:\$PATH\"" >> ~/.zshrc

Or if you are using a bash terminal:

echo "# For tkinter 
export PATH=\"/usr/local/opt/tcl-tk/bin:\$PATH\"" >> ~/.bashrc

Homebrew

Reference

Python's offical tk upgrade docs

Mizzle answered 21/3, 2023 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.