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()

Recommended Answers

All 2 Replies

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]

im only in the 8th grade srry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.