#!/usr/bin/python # Name : Python/Tk Welcome Message # Author : Terrence Ma # Email : terrence@terrence.com # Web : http://www.terrence.com # Date : 08/31/2001 # License : GNU GPL - http://www.gnu.org/copyleft/gpl.html # Warranty : No Warranty # import lib import time from Tkinter import * # procedure set message def setmessage(): global inname, outname, timenow outname = question_entry.cget("text") timenow = time.asctime(time.localtime(time.time())) hello_name.configure(textvariable = outname) date_time.configure(text = timenow) # set top window top = Tk() # set frame question, hello, date question = Frame(top, relief = "groove", borderwidth = "2") hello = Frame(top) date = Frame(top) # set frame question inname = "Computer User" question_question = Label(question, text = "Please enter your name : ") question_entry = Entry(question, text = inname, width = "16", relief = "sunken") question_entry.insert(0, inname) # bind("<>") needs setmessage(event), button(command) needs setmessage() # see http://www.pythonware.com/library/tkinter/introduction/ # question_entry.bind("", setmessage) question_button = Button(question, text = "Submit", command = setmessage) # set frame hello, date outname = question_entry.cget("text") timenow = time.asctime(time.localtime(time.time())) # cget() is not fully implemented, use textvariable hello_mess01 = Label(hello, text = "Hello") hello_name = Label(hello, textvariable = outname) hello_mess02 = Label(hello, text = ", welcome to this application !") date_mess01 = Label(date, text = "Time is now") date_time = Label(date, text = timenow) # draw frames top.title("Python/Tk Welcome Message") question_question.pack(side = "left") question_entry.pack(side = "left") question_button.pack(side = "left") hello_mess01.pack(side = "left") hello_name.pack(side = "left") hello_mess02.pack(side = "left") date_mess01.pack(side = "left") date_time.pack(side = "left") question.pack(side = "top") hello.pack(side = "top") date.pack(side = "top") question_entry.focus() top.mainloop()