Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. from Tkinter import * # This indicates the python interface of a Gui
  2.  
  3. root = Tk() # this indicates base name of window
  4.  
  5. root.resizable(0,0)
  6.  
  7. root.title("Display Strings") # Title of GUI window
  8.  
  9. def displayOutput():
  10. print "working"
  11.  
  12. userName=entName.get()
  13. print userName
  14. length=len(userName)
  15. print length
  16. welcome="Welcome to python,"+ userName + "!"
  17. print welcome
  18. outputName.configure(text=welcome)
  19. message="Your name length shown below"
  20. outputWelcomeMsg.configure(text=message)
  21. namelength="Username length: + "+str(length)
  22. outputUserLength.configure(text=namelength)
  23.  
  24. #==========GUI Section Button and Label section ==================
  25. lblTitle=Label(root, text="Task 2", font=('Verdana', 28) ) # this indicates the title of the module
  26. lblTitle.grid(row=0, column=0, columnspan=2,pady=2, ipady=2, padx=10)
  27.  
  28. lblName=Label(root, text="What is your name?", font=('Arial', 14))# This indicates
  29. lblName.grid(row=1, column=0, sticky=W)
  30.  
  31. entName=Entry(root, width=8)
  32. entName.grid(row=1, column=1, sticky=W)
  33.  
  34. btnSubmit=Button(root, text="submit",command=displayOutput)
  35. btnSubmit.grid(row=2, column=0, columnspan=2)
  36.  
  37. outputName=Label(root, text=".....", font=('Arial', 14) )
  38. outputName.grid(row=3, column=0, sticky=W, columnspan=2)
  39.  
  40. outputWelcomeMsg=Label(root, justify=LEFT, text="...", font=('Arial', 14) )
  41. outputWelcomeMsg.grid(row=4, column=0, columnspan=2, sticky=W)
  42.  
  43. outputUserLength=Label(root, text="...", font=('Arial', 14) )
  44. outputUserLength.grid(row=5, column=0, columnspan=2, sticky=W)
  45.  
  46. 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