Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import * # This indicates the python interface of a Gui
- root = Tk() # this indicates base name of window
- root.resizable(0,0)
- root.title("Display Strings") # Title of GUI window
- def displayOutput():
- print "working"
- userName=entName.get()
- print userName
- length=len(userName)
- print length
- welcome="Welcome to python,"+ userName + "!"
- print welcome
- outputName.configure(text=welcome)
- message="Your name length shown below"
- outputWelcomeMsg.configure(text=message)
- namelength="Username length: + "+str(length)
- outputUserLength.configure(text=namelength)
- #==========GUI Section Button and Label section ==================
- lblTitle=Label(root, text="Task 2", font=('Verdana', 28) ) # this indicates the title of the module
- lblTitle.grid(row=0, column=0, columnspan=2,pady=2, ipady=2, padx=10)
- lblName=Label(root, text="What is your name?", font=('Arial', 14))# This indicates
- lblName.grid(row=1, column=0, sticky=W)
- entName=Entry(root, width=8)
- entName.grid(row=1, column=1, sticky=W)
- btnSubmit=Button(root, text="submit",command=displayOutput)
- btnSubmit.grid(row=2, column=0, columnspan=2)
- outputName=Label(root, text=".....", font=('Arial', 14) )
- outputName.grid(row=3, column=0, sticky=W, columnspan=2)
- outputWelcomeMsg=Label(root, justify=LEFT, text="...", font=('Arial', 14) )
- outputWelcomeMsg.grid(row=4, column=0, columnspan=2, sticky=W)
- outputUserLength=Label(root, text="...", font=('Arial', 14) )
- outputUserLength.grid(row=5, column=0, columnspan=2, sticky=W)
- root.mainloop() # this here indicates that you must close the module or else it will come up with error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement