You are not logged in.

#1 2011-04-16 16:47:58

Tisse
Member
Registered: 2010-01-14
Posts: 13

[SOLVED] How to use python tkinter

Hi,

I am thinking about writing a small little program with a GUI that should work in both linux and windows. For this my plan is to use python and tkinter and I've installed eclipse and pydev. But I've failed to even import tkinter in my program!

I see that tkinter is available in /usr/lib/python3.2/ but do I need to do anything to make it available?

I've never done any GUI-programming before, only some small scripts in various languages so I am a beginner...

Last edited by Tisse (2011-04-20 16:51:12)

Offline

#2 2011-04-16 16:57:11

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [SOLVED] How to use python tkinter

I recommend you to use pyqt. You have good documentation, qt-designer to create your gui and looks nice.

Offline

#3 2011-04-16 17:07:51

Tisse
Member
Registered: 2010-01-14
Posts: 13

Re: [SOLVED] How to use python tkinter

Ok. Does it work and look good on a windows machine as well?

Is it easy to start using it in arch-linux?

Offline

#4 2011-04-16 17:16:41

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,308

Re: [SOLVED] How to use python tkinter

I'll throw in my opinion as well.

I use, and love wxPython, the Python bindings for wxWidgets.  It is similar to PyQt in terms of learning curve. It is fast, it runs well on Linux and Windows.

The problem I've with PyQt is the license.  On my own time, I fully embrace the GPL.  At work, however, I must consider the ramifications of that license, the requirement to distribute source, and non-disclosure agreements we have in place with our partners.  wxPtyhon is LGPL.  Even though Qt is LGPL, PyQt is GPL.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2011-04-16 17:34:08

Tisse
Member
Registered: 2010-01-14
Posts: 13

Re: [SOLVED] How to use python tkinter

Thanks. The license type doesn't really matter for me, I will create a small program that I will spread as open source if it gets good enough. So I might look at both of them.

Are wxPython and PyQT easily installed on arch-linux and easy to setup using eclipse and pydev?

Offline

#6 2011-04-16 21:15:26

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,308

Re: [SOLVED] How to use python tkinter

I know Qt is well supported by Eclipse, but I have not tried using Eclipse to explore the PyQt library.  Python presents some challenges to IDEs because auto completion for a loosely typed, reflective language.  I have had some difficulties with C++ and Qt in Eclipse during debugging using Arch's standard Qt installation.  Also, there is a program that is part of PyQt that takes the xml files that define a GUI and translate them into Python.  I do not know how smoothly that program integrates with the build system.

wxPython is well supported by Eclipse and does a nice job of auto completion.  The documentation for PyQt is awful.  Fortunately, the documentation for wxWidgets is pretty good and can be used to infer how to use wxPython.  There is no problem with the integration of the GUI design tools -- because there aren't any tongue 

In general, I find wxPython (and wxWidgets) to be much lighter weight than PyQt and Qt.  Also, it is a lot less trouble to install wxWidgets on Windows than Qt.  (IIRC, Qt is MinGW based, whereas wxWidgets can be compiled with minGW, Borland, or Visual Studio)  Qt installs bring in all of the MinGW cruft, whereas wxWidgets does not.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#7 2011-04-17 14:08:38

Tisse
Member
Registered: 2010-01-14
Posts: 13

Re: [SOLVED] How to use python tkinter

I tried to use wxPython but it didn't work for me, the module wasn't found. Could it be because I have several versions of python installed (3.2 and some older versions)?

I tried a "hello world" for PyQT and that worked for me out of the box. But after have read your comment I would like to get wxPython working and use that instead. Is there a guide or something that explains how to get it up and running on arch?

Offline

#8 2011-04-17 18:00:35

bunburya
Member
From: Dublin, Ireland
Registered: 2010-09-06
Posts: 64

Re: [SOLVED] How to use python tkinter

Tisse wrote:

I tried to use wxPython but it didn't work for me, the module wasn't found. Could it be because I have several versions of python installed (3.2 and some older versions)?

I tried a "hello world" for PyQT and that worked for me out of the box. But after have read your comment I would like to get wxPython working and use that instead. Is there a guide or something that explains how to get it up and running on arch?

wxPython has not yet been ported to Python 3. Of the 4 main GUI toolkits for Python (wxPython, PyQt, PyGtk and Tkinter) only PyQt and Tkinter have been ported.

If you really want to use wxPython, you'll have to write your program in Python 2.

Offline

#9 2011-04-17 23:08:37

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [SOLVED] How to use python tkinter

In general, I find wxPython (and wxWidgets) to be much lighter weight than PyQt and Qt.  Also, it is a lot less trouble to install wxWidgets on Windows than Qt.  (IIRC, Qt is MinGW based, whereas wxWidgets can be compiled with minGW, Borland, or Visual Studio)  Qt installs bring in all of the MinGW cruft, whereas wxWidgets does not.

This thing you say about mingw is not true:
http://doc.qt.nokia.com/vs-add-in-1.1.7/index.html

In fact, I have developed an application with pyqt and never heard of mingw before a few weeks, when I needed to recompile qt with mysql support (the mysql binary does not come with the opensource version of qt... if you need help with this just say it).

Then, using py2exe I can bundle the whole application in a single exe that runs smoothly. The application has more files, but they are external command line tools and configuration files... no qt needed on the target computer.

Last edited by Pajaro (2011-04-17 23:09:43)

Offline

#10 2011-04-18 03:08:26

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,308

Re: [SOLVED] How to use python tkinter

Pajaro wrote:

This thing you say about mingw is not true:
http://doc.qt.nokia.com/vs-add-in-1.1.7/index.html
...

Fair enough, I stand corrected (I did say IIRC).  I generally avoid the non-express versions of Visual Studio.  I also tend to cross compile under Linux rather than use Windows.  This may have been the root of my misunderstanding.

Thanks


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#11 2011-04-18 05:39:22

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [SOLVED] How to use python tkinter

Sorry. I see that I missunderstood, and I know why. What is IIRC?
http://www.acronymfinder.com/IIRC.html
Between the 21 choices I guess you didn't mean 'Iraqi Islamic Reconciliation Conference', so I vote for 'If I Remember Correctly'. Am I right? smile

Last edited by Pajaro (2011-04-18 05:40:39)

Offline

#12 2011-04-18 13:13:55

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,308

Re: [SOLVED] How to use python tkinter

Pajaro wrote:

Between the 21 choices I guess you didn't mean 'Iraqi Islamic Reconciliation Conference', so I vote for 'If I Remember Correctly'. Am I right? smile

Yes.

IMHO,  perhaps I should be more careful with abbreviations -- ROTFLOL,
As to Qt perhaps I should RTFM


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#13 2011-04-18 14:43:30

Tisse
Member
Registered: 2010-01-14
Posts: 13

Re: [SOLVED] How to use python tkinter

Hi,

Thanks for all advice. I believe it is best that I start with one and see what I can do with it. As a beginner with a limited amount of free time it will probably take a while before I reach the limitations of each choice.

So I better stop talking about creating a cool python application and start doing :-)

Offline

#14 2011-04-18 17:03:53

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: [SOLVED] How to use python tkinter

Tisse,
Going back to Tkinter topic, what did you try that did not work exactly?

Offline

#15 2011-04-19 12:51:04

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: [SOLVED] How to use python tkinter

Tisse probably just needs to install the tk package...

Offline

#16 2011-04-19 16:26:23

Tisse
Member
Registered: 2010-01-14
Posts: 13

Re: [SOLVED] How to use python tkinter

Hi,

I tried a simple "hello world"

from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()

But the output were:
Traceback (most recent call last):
  File "/home/tisse/workspace/PyTest/src/HelloWorld.py", line 6, in <module>
    from Tkinter import *
ImportError: No module named Tkinter


And I do have tk installed:
extra/tk 8.5.9-1 [installed]
    A windowing toolkit for use with tcl

Offline

#17 2011-04-19 20:35:56

bunburya
Member
From: Dublin, Ireland
Registered: 2010-09-06
Posts: 64

Re: [SOLVED] How to use python tkinter

Tisse wrote:

Hi,

I tried a simple "hello world"

from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()

But the output were:
Traceback (most recent call last):
  File "/home/tisse/workspace/PyTest/src/HelloWorld.py", line 6, in <module>
    from Tkinter import *
ImportError: No module named Tkinter


And I do have tk installed:
extra/tk 8.5.9-1 [installed]
    A windowing toolkit for use with tcl

In Python 3, you import tkinter, not Tkinter (lower case "t").

Offline

#18 2011-04-19 22:51:29

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: [SOLVED] How to use python tkinter

Common practice is to go this way:
from tkinter import *
from tkinter import ttk

That way, theme tk widget will be used in favor of regular widgets.
Here is a very good place to get you started http://www.tkdocs.com/tutorial/firstexample.html

Offline

#19 2011-04-20 16:49:14

Tisse
Member
Registered: 2010-01-14
Posts: 13

Re: [SOLVED] How to use python tkinter

So it was so simple... I must have read an old tutorial.

Thanks for the advice, it works now!

Offline

Board footer

Powered by FluxBB