954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

TURN THIS ASSIGNMENT UserID INTO GUI, CAN YOU HELP ME

Did I do this right and can you please help me. This program uses a GUI to input a user's first and last name,
and construct and display a UserID. Although the program 'runs',
there are several problems with it. Fix each of these problems
in turn:

1) The text and corresponding entry box for 'Last Name' does
not align with those for 'First Name'. Correct this.
2) Provide the code to draw a Rectangle around the 'button'
text object, so that it looks like a button.
3) The program as written always produces the same UserID, 'frodo'.
Change this so the UserID will be the first six letters of the
last name and the first character of the first name, all in
lowercase. For example, if the user entered 'Bilbo' and 'Baggins'
for first and last names, respectively, his UserId would be
'bagginb'. [Hint: you may want to use the lower() function is
the string library for this.]
4) Add the code necessary to change the text of the button text
object to 'Quit' after the UserID has been displayed :o :o

from graphics import * 

def main(): 

win = GraphWin("UserID Assignment", 400, 300) 
win.setCoords(0,0, 4,3) 

# draw the interface 
Text(Point(0.5, 2.5), "First Name").draw(win) 
Text(Point(0.8, 1.7), " Last Name").draw(win) 
fName = Entry(Point(2.0, 2.5), 20) 
fName.setText("") 
fName.draw(win) 
lName = Entry(Point(2.5, 2.0), 20) 
fName.setText("") 
lName.draw(win) 
button = Text(Point(2.0, 1.0), "Get UserID") 
button.draw(win) 

output = Text(Point(2.0, 0.3), \ 
"Enter your name and click 'Get UserID'") 
output.draw(win) 

# wait for mouse click 
win.getMouse() 

# obtain input and construct userid 
first = fName.getText() 
last = lName.getText() 
userid = "frodo" 

# display result 
output.setText("Your UserID is " + userid + ".") 

# all done 
win.getMouse() 
win.close() 

main()
butterflyTee
Light Poster
43 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

The module "graphics" is foreign to me. Is this something your teacher has writtten?

Also everything belonging to function main() should be indented properly!

Replace
userid = "frodo"
with
userid = last.lower()[:6] + first.lower()[:1]

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

im only in the 8th grade srry

mechdriver
Newbie Poster
7 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You