Tkinter Tutorial 1

This is a first in a short series on using python-tkinter

based on python2.x seiries (python-tk)

If using or porting to python 3 you need (python3-tk package, YMMV)

I am using xubuntu 14.04 to create the programs for this tutorial,  the programs work equally well on the raspberry pi.

For other systems you may need to adapt the program so it works.

 

CREATE A WINDOW IN PYTHON / TKINTER

 

Once you are familiar with python enough to write small programs, you may want to use whatr you know and created windowed applications.

 

#!/usr/bin/env python
import Tkinter # note use of caps
from Tkinter import *
 
window = Tk()
window.title('GUI Tkinter 1')
window.geometry("300x250") # w x h
window.resizable(0,0)
 
window.mainloop()

 

window1

 

 

 

 

 

 

 

 

 

 

How it works

code Explanation
#!/usr/bin/env python

This tells the interpreter to use python

importTkinter
from Tkinter import*

This imports the Tkinter module we need

window = Tk()

Create window object

window.title('GUI Tkinter 1')

Define the Window title

window.geometry("300x250")# w x h

Set window size width x height

window.resizable(0,0)

Define if we can resize the window or not

window.mainloop()

This displays the window

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Anti Spam by WP-SpamShield