I'm learning Tkinter right now and trying to work through my first issue, but finding Google hasn't been helpful.
I'm running this code on Mac OS X 10.15.1 (Catalina)
I'm using Python 3.7 and my code looks like so (lots of boilerplate per PEP8 standards):
"""
Experiments in tkinter
"""
import tkinter as tk
def main():
"""
Main entrypoint
"""
tk._test()
if __name__ == "__main__":
main()
This outputs the following warning to the console:
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.
It also displays a window with completely blank buttons:
From my understanding these buttons should say "Click Me" and "Quit".
Also when I click on the top button it flashes black for a second like so:
After which the button is wider than before:
I assume the Tk version error may be related to the output behavior. However I can't seem to find a way to update Tk. What should I do here?
Update
After seeing #ShayneLoyd's answer (suggesting I needed an updated version of Python with an updated version of Tk) I began looking around some more and found this post on the Apple Discussion Boards which suggests you can use homebrew to install a version of Python which link's homebrew's own installed version of Tk. I tried this and it failed, so I Google'd the issue and found this StackOverflow post which seemed to suggest I can install
ActiveTcl and it will work.
I installed ActiveTcl from ActiveState and went back to my project. At first, I ran it like so:
$> cd ~/Source/experiments/python/tkinter
$> ./test.py
This actually worked! I could read the buttons and it behaved like it should. Then I realized I was not using pipenv, so I did a quick test:
$> pipenv run ./test.py
Now I was back to the failure state. I updated my script to display the Tcl and Tk version and sure enough when I used pipenv it was loading Tcl/Tk 8.5.9 but when I didn't use pipenv it was loading 8.6.9
So how do I fix pipenv now?
For anyone who's having the same issue and cannot switch Python version, you can easily bypass the "not showing text on buttons" problem by changing MacOs theme. System Preferences>General>Light Mode.
You should have in mind that you may encounter other problems.
After a few hours messing with it I figured it out!
The Pipfile contained a reference to Python version 3.7
Therefore pipenv install was searching my machine for any 3.7 version of Python installed. The version it found was Homebrew's, which has Tk 8.5.9 statically linked.
By updating the Pipfile to require Python 3.8 my machine started pulling my system Python, which uses the dynamically linked Tk, which I had successfully updated to 8.6.9
Related
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
Being a complete begginer in python, I decided to install the python interpreter 3.4.4, and also PyDev plugin for eclipse IDE. I am also using windows 10.
I have encountered a problem regarding certain imports, namely : from PIL import Image, ImageTk, which is apparently an unresolved import.
I have looked at certain questions which were similar to my situation, but most of them gave a solution like installing packaged from the linux apt-get. Here are some topics I visited :
Uninstalling and reinstalling Pillow and pip,
Installing pillow-imaging-tk on Ubuntu,
This topic which left me very confused,
This one seemed helpful, but is on Unix OS again
So please, could someone explain to me why I am seeing this error, and how could I correct it if I absolutely want to use Eclipse, Pydev, windows 10 and Python 3.
Found the solution, here's what I did:
Set the PYTHONPATH like it is shown in this article, make sure python.exe is accessible via cmd,
Via cmd, type pip install pillow. Alternatively, you can enter the same command from Windows+R,
(Not sure if relevant step) Via eclipse, Windows->Preferences->PyDev->PythonInterpreterremove your interpreter to re-add it,
Restart eclipse.
For Python import problems in PyDev, the project web site has a page on interpreter configuration that is a good place to start. I recently had a similar problem that I solved by adding a module to the forced builtins tab.
I'm learning python + gtk3+ so I was looking for an IDE to help me. Is there any way to get code completion with PyGObject? I've really tried EVERYTHING I can think of.
I have pycharm build 138.2401 where this bug: https://youtrack.jetbrains.com/issue/PY-6932 is supposed to be fixed but I can't get any code suggestions.
This simple code would raise a warning (Gtk is not found):
#!/usr/bin/python3
from gi.repository import Gtk
Also, using fakegir doesn't work either (and it does work with WingIDE). Here is my project start script in case I'm doing something (horribly) wrong:
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
sys.path.append(self,"/home/obok/.cache/fakegir/")
2020 Fix
will post a fix here that works for me it might help someone
pycharm version: 2020.1 community
os: Manjaro kde
project interpreter: python 3.8 system wide "not a virtual env"
Gtk completion is working only from pycharm terminal, but not from editor area
the proposed solution of putting mouse pointer at Gtk keyword and Then press alt+enter, simply doesn't work because it didn't show option "Generate stubs for binary module"
solution Steps:
Change this line in idea.properties file to
idea.max.content.load.filesize=20000, in may case i used sudo nano /usr/share/pycharm/bin/idea.propertie to edit this file, yours might be in different place, use locate or find cmd to findout.
create a vertual env from pycharm for your current project.
Install Gtk: follow the exact steps in official website here otherwise it will fail, you might need to install package "wheel" into your venv
After finish installing successfully, click on Gtk in from gi.repository import Gtk then press alt+enter, and select "Generate stubs for binary module".
wait.......... until finished.
pycharm will complain there is no type hint for Gtk and offer to
install "PyGobject-stubs" DON'T install it, because it cause
problem.
After all done ... restart Pycharm.
Pycharm will start but will take some more time again for indexing and finally all work.
Using the page you suggested, I tested the solution at the bottom of the page, and guess what, it worked! It took some indexing from Pycharm, but everything now autocompletes!
Just write:
from gi.repository import Gtk
Then press alt+enter, and select "Generate stubs for binary module"
I am trying to install wxPython on my Ubuntu 12.10 but with no success. I have gone through all the answers given on this website.
Can someone please help me in this or point me in the right direction.
Initially, I tried http://wxpython.org/BUILD.html but then I came to know that it is in the repository, I ran "sudo apt-get install install python-wxgtk2.8", it installed without any error but then, when I run it, it is still unavailable. I guess I am doing something in the running step.
Also, although it is working in Eclipse using PyDev, but I am getting this warning " LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent."" after I close the application and the status bar is also not working,
Here is my code:
import wx
class naman(wx.Frame):
def __init__(self,parent,id): # #ReservedAssignment
wx.Frame.__init__(self,parent,id,'Frame aka Window', size=(300,200))
panel=wx.Panel(self)
statusbar=self.CreateStatusBar()
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
first.Append(wx.NewId(),"New Window", "This opens a new window")
first.Append(wx.NewId(),"Open...", "This will open")
second.Append(wx.NewId(),"Undo", "This will undo")
second.Append(wx.NewId(),"Redo", "This will redo")
menubar.Append(first,"File")
menubar.Append(second,"Edit")
self.SetMenuBar(menubar)
if __name__=='__main__':
app=wx.PySimpleApp()
frame=naman(parent=None,id=-1)
frame.Show()
app.MainLoop()
If someone can tell why I am getting this warning and why status bar is not working, that would be great too!! Then, I can continue working in eclipse itself and don't bother about wxPython.
PS: I have Python2.7 and Python3.3 already installed.
Thanks in advance.
You need to install wxPython Phoenix, not 2.8. The 2.8 series and the 2.9 Classic series are only Python 2.x compatible. You'll have to grab a Phoenix snapshot to build against as it is the only version that is Python 3 compatible. You can get one here:
http://wxpython.org/Phoenix/snapshot-builds/
Note that Phoenix is very beta in that it only supports the core widgets currently. Most of the custom widgets, like those in wx.lib, are still being ported. See http://wiki.wxpython.org/ProjectPhoenix for more information.
(New in python+kivy here).
Hi, I'm trying to get python with Kivy up in running and I just wanted to know if there's a way to run Kivy apps in PyCharm since I'm getting an error:
Traceback (most recent call last):
File "C:/Kivy/kivy/examples/tutorials/pong/main.py", line 1, in <module>
import kivy
ImportError: No module named kivy
when loading this file with pycharm, notice that that's the sample game out of the box, I can run the app via right click->sendTo->kivy.bat but I don't think that large scale apps actually do it that way -.- there must be a simpler(and hopefully more graphic) way to use Kivy, after a lot of asking to Dr. Google I give up, Thanks in advance!:)
BTW: My main interest is making apps that makes basic database requests and at the same time are GUI friendly , Kivy was my first option next to WX but if there are any suggestions they are welcome :)
I just put up a tutorial on how to setup pycharm & kivy on os x
Short Version for Windows (I assume this will work):
After you install kivy, you need to create a python interpreter for kivy - if you already had python installed, it's the wrong python to do Kivy work. Check C:/Kivy/kivy/ or the contents of kivy.bat to get the path to the python.exe distributed with kivy ( I found C:\Kivy141\Python\python.exe on one page, but that may be if you install kivy manually)
When you find it, your kivy project python interpreter needt to be that one.
Good luck!
With PyCharm on OSX I had the same problem and solved it by creating a VirtualEnv in PyCharm (see PyCharm docs for this) and some Kivy paths to the virtualenv. You can find this by selecting the VirtualEnv and select the tab "Paths".
You can probably find out the correct paths by inspecting the kivy.bat file. I did something similar on the Mac.
I wanted to include a picture to show my paths settings, but my Stackoverflow karma level doesn't allow this.
PyCharm 4.0 changed the answer, now it's just set some environment variables. I updated the Kivy Wiki for setting up PyCharm on OSX
For OSX 10.10.2, kivy 1.9.0, and Pycharm 5.0.2 (free Community Edition), the instructions at the link below worked for me:
Setting up Kivy 1.9.0 with PyCharm 4.5 EAP on OS X 10.10.3
Substitute PyCharm for PyCharm-EAP in the instructions(which only occurs once).
I entered each Environment variable separately, rather than pasting them in as one long string.
Pay attention to the titles of the windows where you enter things. The instructions tell you EXACTLY which window you should be looking at.
To anyone that may see this:
Follow the wiki guide to create the symlink.
In Pycharm, add a local file for the project interpreter, then click the "more" button, go to the pencil, and manually change the link to /Applications/Kivy.app/Contents/Resources/script . That's how I got mine to work, latest PyCharm CE, Kivy, Python 3.5, and El Capitan