Using Tkinter on OSX Mountain Lion 8.2 - python

I'm working on learning to make GUIs with Tkinter for Python programs and I have run into a bunch of problems:
Attempting to run from Tkinter import filedialog I get ImportError: cannot import name filedialog. Elsewhere I have seen it called with the lowercase tkinter (which I think is for Python 3 only) but it does not recognize that as existing ImportError: No module named tkinter. Yet running from Tkinter import * works and I'm able to create the sample hello world from the tutorial.
My only guess is that it is attempting to use an obsolete version of Tkinter that shipped with OSX. Yet considering how new Mountain Lion is, I have to wonder how obsolete it would really be. My assumption is that upon installing Python 2.7 myself, if I run from IDLE, it should work, but instead I get exactly the same thing above from the IDLE shell.
So after that I tried sudo pip install tkinter and sudo pip install Tkinter from the Unix terminal, but I get back No distributions at all found for update
So I start looking into documentation on Tkinter itself, and I come across Tcl/Tk instructions for Mac OS X which states:
Important: If you are using Mac OS X 10.8, 10.7 or 10.6, use IDLE or tkinter from a 64-bit/32-bit Python installer only with ActiveTcl 8.5 installed. If you cannot install ActiveTcl 8.5, use a 32-bit-only installer instead.
So I find my OS in the table they provide and see that they recommend ActiveTcl8.5.11, but unfortunately, the download link is broken.
So I'm completely at a loss here. Any help would be appreciated.

If you want to implement a File Dialog, have a look at tkFileDialog. It is a seperate module & not part of Tkinter module.
You can use it by directly importing it:
import tkFileDialog

Related

windows tkinter install python 3.7.4

installed PYTHON 3.7.4 from the python.org website. Working on a windows 10 machine. everywhere it says tkinter should be part of it but it seems like it's not. I need help installing it.
This is the official documentation for the standard library Tkinter created by the folks at Python Software Foundation :
Tkinter
This will definitely help you install, import and get started with Tkinter on your Windows system.
For importing errors while trying to use Tkinter, please note :
The root of the problem is that the Tkinter module is named Tkinter (capital "T") in python 2.x, and tkinter (lowercase "t") in python 3.x.
To make your code work in both Python 2 and 3 you can do something like this:
try:
# for Python2
from Tkinter import *
except ImportError:
# for Python3
from tkinter import *
But since you've already mentioned that you're on Python 3.7.4, this import statement will suffice :
import tkinter as tk
Tkinter is built in with every Python installation.
I don't know if you typed the command wrong, but this is the proper way.
import Tkinter as tk
Note: There is a Capital T at the beginning of Tkinter.
In Python 3 for you,
import tkinter as tk
Note: You might accidentally deleted it in the folder of python so you could just download python again.
Below from https://pypi.org/project/PySimpleGUI/:
Python 3.7
If you must run 3.7, try 3.7.2. It does work with PySimpleGUI with no known issues.
PySimpleGUI with Python 3.7.3 and 3.7.4+. tkinter is having issues with all the newer releases. Things like Table colors stopped working entirely. It's unclear if there's been a change that makes the tkinter API no longer working which means they are not backwards compatible. That would be a real shame. If so, more work needs to be done in PySimpleGUI
Can you import tkinter by import tkinter?

Getting error using Tkinter in python on mac OS X

I tried to run a nltk code for drawing parse trees. I got the error that tkinter module is not installed.
These are the error messages I got:
1. UserWarning: nltk.draw package not loaded (please install Tkinter library).
warnings.warn("nltk.draw package not loaded")
2. import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
After some searches I installed the ActiveTcl 8.5.18.0 using this instructions.
But when I try to run my code I still get the sam error. I tried
import Tkinter
but I get the second error message above again.
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
I also looked at Tkinter documentations and it is mentioned that the correct installation of Tkinter can be verified by running the following command which again gives me another error.
command: python -m tkinter
error: /usr/local/opt/python/bin/python2.7: No module named tkinter
I found this answers on Stackoverflow for my problem but they are either not very clear or not applicable to my case.
How to get tkinter working with Ubuntu's default Python 2.7 install?
Problems: tk-dev is not available for OS X (it is same as ActiveTcl) and I couldn't figure out how to rebuilt my python using make
Tkinter: "Python may not be configured for Tk"
Problems: very vague. I don't know what should I do
please help.
You should install ActivePython rather than ActiveTcl, and use it as your preferred Python.
The problem is your Python install isn't picking up your Tcl install, and the simplest way to solve that is to install a Python version that is configured for Tk, which ActivePython is: http://www.activestate.com/activepython
The issue is that the _tkinter Python module is not installed in your build, which is a required bridge between Python and Tk. You will have to reinstall nltk and any other packages you are using, unfortunately, as the versions you have will be installed for your current Python and not your new one.

Fixing Python 3 tkinter issues on Mac with a virtualenv

I think the short version of this question is: How do I get a virtualenv running Python 3.5 to point to the correct version of ActiveTcl on a Mac?
Here's the longer version:
I'm trying to run this Korg Electribe sample editor project on a Mac. The author has only tested it on Windows, and based on the screenshots, it appears to work. I've been able to run the basic python script fine, but as I mention in an issue that I've opened, the full window turns black after loading a file.
After doing some research, I've found that there is a known issue with Aqua Cocoa Tk, and python.org has provided some instrunctions about how to fix tkinter for Mac OS 10.9 and up. I've attempted installing both of the suggested ActiveTcl (8.5.18.0) as well as the newer 8.6.x.x version without success.
I'm pretty sure this is a different issue than Tkinter not working mac osx el capitan, since the script does run, and the window is drawn properly on launch. It's only after I've attempted to load a .all file (there's a sample file in the Github issue) that the screen goes black.
After some more research, I've found this question that seems related, but is specific to Windows: TKinter in a Virtualenv
I'm under the impression that if I can figure out what to set TCL_LIBRARY to, that I'll be able to make some head-way, but I can't seem to find that information for the packages listed on python.org.
Somewhat related, it would also seem to be helpful if I could figure out which version of Tcl/Tk that tkinter is pointing to from within Python, so if anyone could help with that as well, I'd greatly appreciate it.
Thanks!
I succeeded in using tkinter in a python3 virtualenv on OSX 10.13 by :
installing the official OSX Python 3 from https://www.python.org/
installing activeTcl from https://www.activestate.com/activetcl
creating a new virtualenv
mkvirtualenv myenv --python=python3
locating the tkinter location in the Python3 directory. For me it was here :
/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter
creating a symbolic link in the virtualenv library pointing to the tkinter location
cd ~/.virtualenvs/myenv/lib/python3.6
ln -s /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter tkinter

Cannot get python IDLE 2.7, 3.3 to run - OS X

I am running a MacBook Pro with 8gb of memory and a 2.5GHz processor. I run OS X Mavericks, but this problem has happened on other operating systems as well. when I try to open the editor, or even open a python file, this happens:
This has been a problem since I got into python. I have tried as many versions as I can, and the same screen pops up. Please help
I recently also upgraded a friends iMac to OS X 10.9 Mavericks and her Python to 2.7.6. If you mount the python-2.7.6-macosx10.6.dmg disk image there's a text file named ReadMe.txt. If you ahem, actually read it, right near the beginning it says:
**** IMPORTANT ****
Update your version of Tcl/Tk to use IDLE or other Tk applications
To use IDLE or other programs that use the Tkinter graphical user
interface toolkit, you may need to install a newer third-party version
of the Tcl/Tk frameworks. Visit
http://www.python.org/download/mac/tcltk/ for current information
about supported and recommended versions of Tcl/Tk for this version of
Python and of Mac OS X.
Here's what http://www.python.org/download/mac/tcltk currently looks like (my highlighting):
To summarize: You need to download and install ActiveTcl 8.5.15.1 (which is mislabeled ActiveTcl 8.5.15.0) from ActiveState's webpage. After doing that you should be able to run IDLE:
I haven't actually tried to do it yet, but from what I read it sounds like the same process applies to Python 3.3.3 and its IDLE app.
I was having the exact same problem.
I was finally able to install Python (and IDLE) via MacPorts by also installing a package called "pyXX-tkinter" -- where XX is the version, e.g. py34-tkinter for Python 3.4.

Using pygame on a mac?

I was trying to get pygame on my mac to work. I got it running in terminal. But I run into issues when trying to use it with netbeans or trying to run the file. It gives me the error
from pygame.locals import *
ImportError: No module named locals
any help? Thanks!
If you still want to use netbeans, I think you should take a look at ActivePython
Activepython basically lets you install different pythons on your machine and be able to select between them (there's a lot more features I'm sure).
My advice would be to go to the console and type
>python
>>> from pygame.locals import *
If that works, ctrl-c out and do a python -v to find out the version.
Once you have the version, you can use activepython to select that version by running:
sudo pysel [version]. For instance for python2.7:
sudo pysel 2.7
This should switch the python over and your netbeans should (hopefully) work with it.

Categories

Resources