So where's Tkinter then?


6 posts
by pine » Sun Jun 24, 2012 8:39 pm
Have the pi running with Debian squeeze, and wanted to run some previously written python scripts. Quickly discovered tkinter was not installed. Does this mean it's not been distributed within the Debian image, or that it's there but needs to be activated?

As a linux newbie (not sure I'll ever understand the linux file structure!), any advice would be appreciated, but pls keep it simple!
Posts: 10
Joined: Sun Jun 24, 2012 8:32 pm
by andyl » Sun Jun 24, 2012 9:33 pm
Not installed by default - to install do

Code: Select all
sudo apt-get install python-tk
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by pine » Mon Jun 25, 2012 8:49 pm
Andy: many thanks. Worked second time, because the tkinter install also needed to access the Debian archive on their site, and as the Pi was not connected to my router first time round, it failed. Second time, with the ethernet cable in place it all seemed to work, accessing an additional 4.5MB from archive.

However: when I ran my software, the start up text appeared as expected in the terminal, but when the program attempted to create the GUI widgets (frame, canvas, text box and a number of buttons), it crashed with:

Traceback (most recent call last):
File "GUI.py", line 670, in <module> app = Application()
File "GUI.py", line 233, in __init__
Frame.__init__(self,master)
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line1926 in __init__
BaseWidget._setup(self, master, cnf)
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line1901 in _setup
_default_root = Tk()
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line1646 in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantab???
???cts, useTk, sync, use)
Tkinter.TclError: no display name and no $DISPLAY environment variable

(I captured this with a digital camera shot of the TV screen. the ??? are characters I can't make out!)

Perplexing. I already knew the software ran ok with Puppy linux booted off CD on a laptop, so I decided to check the full Debian 6.0 download by loading its ISO into a VM Player virtual machine. Again I had to install Tkinter (getting good at that now!), and again additional stuff was downloaded from the Debian site, about 4.1 MB . My software ran just fine.

So, is this a problem with the Debian SD card image for the Pi?

Anyone else out there with any thoughts?
Posts: 10
Joined: Sun Jun 24, 2012 8:32 pm
by jamesh » Mon Jun 25, 2012 9:40 pm
Is there a desktop running? (i.e. have you run startx)
Volunteer at the Raspberry Pi Foundation, helper at Picademy September, October, November 2014.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 12378
Joined: Sat Jul 30, 2011 7:41 pm
by pine » Tue Jun 26, 2012 7:46 pm
To be honest could not remember whether I'd launched startx or not, so gave it a go. Without startx, problems as above, but running startx first then my prog from inside a terminal .... worked fine! So for software using/generating graphics a desktop must be launched first. Hmmm. A windows management thing?

Anyway, we're firing on all cylinders: somewhat slower than on my laptop (pentium dual core) but only to be expected.

All in all, not a bad 4 days progress since I burnt the image to SD card. Positively setting the world on fire. You could call it pi-rho-mania (sorry, but that's two Greek letters and a Greek word in one pun!).

Thanks again to Jamesh and Andyl for their help and advice.

Guess we can regard this thread closed.
Posts: 10
Joined: Sun Jun 24, 2012 8:32 pm
by andyl » Tue Jun 26, 2012 10:34 pm
pine wrote:To be honest could not remember whether I'd launched startx or not, so gave it a go. Without startx, problems as above, but running startx first then my prog from inside a terminal .... worked fine! So for software using/generating graphics a desktop must be launched first. Hmmm. A windows management thing?


Not quite for a piece of software that uses X Windows (either directly or as in TKInter's case indirectly) you have to be running X.

You can do graphics without running X by using pygame which uses SDL which can write directly to Linux's framebuffer device.

Except that pygame isn't particularly designed for writing GUI based apps - it is designed for games.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am