simplebutton2

simplebutton2.py  [download]

# Simple button program, with actions, like java SimpleButton2

# Weird import for compatibility across Python 2 and Python 3
try:   
	import tkinter   
except ImportError:
	import Tkinter as tkinter   

# Callback function for our button,
# must define it before we refer to it below
def myCallback(): #//*4 Callback
	print ("Button was pushed") #//*4

# Create main frame
top = tkinter.Tk() #//*1 Create main frame

# Put our button in the main frame
# and set button's properties
b1 = tkinter.Button (top) #//*2 Create and install button
b1["text"] = "Push me" #//*3 Set our button's properties
b1["command"] = myCallback #//*4
b1.pack() #//*2

# Start the main GUI loop
top.mainloop() #//*5 Main loop on top window