Introduction to Python


Contents

How to install Python on Linux
How to run a Python program
The basic of Python codes
Data expressions
Built-in functions in Python
Interactive input/output
Conditional statement for Python
Loop structure for Python
Creating your own functions
Python modules
Reading/writing files for Python
Error handling code
Object Oriented Programming (OOP)
Tkinter package for GNU programming


Tkinter package for GNU programming

There is a package called Tkinter to program GNU. Install it by typing "apt-get install python-tk" Here is a basic example using Tkinter.
from Tkinter import *
class Keys(Frame):
   def __init__(self):
       Frame.__init__(self)
       self.txtBox=Text(self)
       #When typing 'quit', the program will exit.
       self.txtBox.bind('quit',self.QuitEvent)
       #The pack() determines the place.
       self.txtBox.pack()
       self.pack()
   def QuitEvent(self,event):
       import sys
       sys.exit()
Make an instance and start the event. The mainloop() is a method in Tkinter to keep editing in the window until you close.
myApp = Keys()
myApp.mainloop()
The typical widgets of Tkinter are: Frame; Button; Entry; Text; Radiobutton; PhotoImage; Listbox; Scrollbar; Checkbutton, etc.

You have to use <space> is for space-key for Tkinter.




Back to Electronics Page

Back to Hiro's Physics Main