On 17/08/18 03:19, Matthew Polack wrote: > 1.) Centre feature > > When I use txt.insert I need to use the feature Peter found... > > center = txt.tag_config("center", justify="center") > txt.insert(0.0, result, "center") > > but in the Enter label section...I could just use it straight away..without > defining it with the tag... > > answerbox = Entry(root, bg="grey", font=("arial", 24, "bold"), justify > ="center") > answerbox.grid(row=15, columnspan=2, padx=0, pady=0, sticky=EW) > > Can you explain why?
That's how the Tcl/Tlk designers decided to do things. tags are a concept that only apply to the Text widget so don't make much sense in a single line Entry. But essentially its an arbitrary design decision taken 30 years ago and we are stuck with it :-) > 2.) When inserting the wording re: 'You have made mistake' or 'Great job' > etc...I found I had to break it up into separate lines...as I was getting > syntax errors. > > txt.insert(0.0, result, "center") > txt.insert(3.0, wordScore, "center") > txt.insert(8.1, score, "center") > > > Is there a way to simply combine all these commands with one txt.insert and > using commas? Not with commas but you can use line breaks inside a triple quoted string and just do a single insert. In fact one of the improvements I'd suggest for your code is to use string formatting to insert the values into your strings before inserting them. eg: fail_str = """ Sorry, you got it wrong, the correct answer was %d Your current score is: %f""" % answer,score txt.insert(1.0, fail_str, "center") > 3.) Is there anything else in this code that looks like a bit of a > glaring...'Coding Rookie' mistake? Or is simply inefficient? I'll send a second reply with inline comments. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor