1.11M Members

Understanding how tkinter works.

 
0
 

I've been trying to read up about how tkinter (or more accurately Tk) works on windows AND linux.
Here's what I've understood so far. Tk is a predefined set of widgets. That is stuff like text boxes, check boxes, drop down lists etc. Tkinter is just a way of translating Tk commands into python. (please correct me if I'm wrong).

So how, then, does Tk manage to provide windows which look 'native' for the different operating systems? For example, if I draw a window with a simple button in linux, it will look just like any other button in the operating system. If I do the same thing on windows, it will look just like a normal button in windows. How does Tk provide different looking windows with the same code?
(I've installed python 3.1 on my windows PC and python came 'out of the box' on my ubuntu linux. I just write code in windows and run it on linux.)

 
0
 

Tkinter is the build in gui(Graphical user interface) of python.
There are many other good gui toolkit like wxpython - PyQt -PyGTK.

Tkinter is just a way of translating Tk commands into python. (please correct me if I'm wrong).

No Tkinter or any other gui toolkit is to display our python code in a graphical way.

if I draw a window with a simple button in linux, it will look just like any other button in the operating system

Yes pretty much,gui toolkit come with many ways to customize look off button and any other widgets.

I like wxpython and it has a cool demo where you can se all widgets live and test them out.
look like this.

Attachments gui_wxpython.jpg 191.34KB
 
0
 

So how, then, does Tk manage to provide windows which look 'native' for the different operating systems?

I don't know the way it technically does it, but my best guess is that it uses an API - application programming interface - to standardize how it draws widgets without being aware of operating system details.

http://en.wikipedia.org/wiki/Application_programming_interface

 
0
 

I don't know the way it technically does it, but my best guess is that it uses an API - application programming interface - to standardize how it draws widgets without being aware of operating system details.

http://en.wikipedia.org/wiki/Application_programming_interface

What do you mean by "Standardize how it draws widgets"? Do you mean that tkinter or Tk uses an API of the system telling the system to draw a certain widget instead of drawing the widget on its own?

 
0
 

What do you mean by "Standardize how it draws widgets"? Do you mean that tkinter or Tk uses an API of the system telling the system to draw a certain widget instead of drawing the widget on its own?

Possibly. I don't know. Tkinter could also define its own API.

 
1
 

Don't overlook the fact that the Python installer you use is specific for the Operating System. If you install Python on a Windows OS, the GUI toolkits will use the Windows GUI. A similar thing goes for Linux or the Mac OSX.

Python source code is largely cross platform, but the actual interpreter is specific to each OS. The GUI toolkits follow the same rule.

 
0
 

So Tkinter (or Tk) does call the operating systems specific GUI software to actually draw the windows? Is that how it creates the 'native' look and feel?

 
1
 

Tkinter is Python's wrapper of the GUI toolkit Tk, originally written in a computer language called TCL. Tkinter has the advantage of a small footprint, also IDLE, the IDE that ships with Python, is written in Tkinter. Whatever program you have has to deal with the Operating System of your computer to be able to do anything.

 
0
 

Yes.. But without getting into all the details, does tkinter itself draw the graphics and get the OS to send it out to the screen or does it tell some component of the operating system to draw the graphics?

 
0
 

Thanks for your reply... I'll check it out and post back

 
0
 

Hi... After reading the documentation, I saw that Tk ultimately relies on Xlib. A wikipedia search on Xlib showed that it was more or less a component of X windows. Since MS Windows doesn't use the X window system, how does tkinter run on windows?

 
0
 

Hi... After reading the documentation, I saw that Tk ultimately relies on Xlib. A wikipedia search on Xlib showed that it was more or less a component of X windows. Since MS Windows doesn't use the X window system, how does tkinter run on windows?

Again, when you install Python on a Windows computer, Tkinter and Tk that install with it rely on the Windows GUI and not Xlib.

 
0
 

ah.. thanks. I think someone ought to correct or modify the python documentation. It just says tkinter uses Xlib. It doesn't mention anything about windows.

Question Answered as of 4 Years Ago by vegaseat, lrh9 and snippsat
 
0
 

Again, when you install Python on a Windows computer, Tkinter and Tk that install with it rely on the Windows GUI and not Xlib.

This does not totally explain why Tkinter windows look so spartan on Windows and look so great on the MAC.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article