Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Using Databases in Python!
You have completed Using Databases in Python!
Preview
Our app has great functionality but some of the UI could be nicer. Let's refine the interfaces a bit and make it nicer to use.
New terms
-
os
- Python module that lets us integrate with the underlying OS -
os.name
- attribute that holds a name for the style of OS -
os.system()
- method to allow Python code to call OS-level programs
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
I don't think that we have a huge number
of tweaks to make to our UI, but
0:00
we definitely have some.
0:03
We need more space around entries, when we
are reading them, and really,
0:05
I'd rather not just keep scrolling the
screen, let's see what we can do.
0:08
Let's start by giving ourselves a little
bit of room after we print out an entry.
0:12
Having the menu right up against the
content makes the content a little
0:17
hard to read.
0:20
So, let's go back to view entry again,
view entries.
0:22
This has been a very popular function for
us to modify.
0:27
So right here after we print out the
content, let's print out two new lines.
0:32
And let's also again print out the equal
signs for the length of the time stamp.
0:38
So two of the lines, and
0:45
then as many equal signs as there are
characters in the time stamps.
0:47
Really, though, I think most of the
unreadableness comes from the fact that
0:50
everything is just printed onto the string
one thing after another,
0:53
just files down, like we've always been
doing.
0:57
We can do better than that, though.
1:01
Let's add in the ability to clear the
screen before we print something out.
1:03
To do this, we're gonna need to call some
OS level stuff,
1:07
so let's bring in the OS library.
1:11
So we come back up here, and we import os.
1:15
And I wanna make a little function that is
called clear.
1:20
And what I want this function to do is to
clear the screen.
1:29
And I'm gonna need this more than once,
that's why I'm making it a function.
1:33
If I was only gonna ever do this one time,
I just write it straight into the code.
1:35
So, what we're gonna do here is os.system,
which let's us call a,
1:39
function on the system, or sorry not a
function a, like a program.
1:43
And we're gonna call CLS if the OS's name
is NT,
1:47
which is Windows I guess if you're on
really old like 98 or
1:54
95 it won't be empty but I do believe
everything else is empty.
1:58
Else, call the function clear or the, the
program clear.
2:02
So we call cls if we're on Windows.
2:08
We call clear if we're on Linux, Mac,
whatever.
2:10
So let's use this where we can.
2:14
I think that whenever they do something on
the menu-
2:18
[BLANK_AUDIO]
2:23
That we should, or whenever we show the
menu rather, we should clear the screen.
2:26
So while choice isn't Q let's call clear.
2:30
And then, I think before we call whatever
the thing is on the menu that we're gonna
2:36
do, like add any entry, or view entries, I
think we should clear the screen again.
2:41
So, we add clear here, and we add clear
here.
2:46
Okay, I think those are pretty good.
2:49
And then I think, the last place,
2:50
maybe that we would put in clear would be
right before we print out an entry.
2:52
It seems like that's one of our more
cluttery areas.
2:58
So we go back to view entries yet
3:00
again, and before we start doing our
prints here, let's call clear.
3:03
All right so it's gonna clear out our, our
screen.
3:10
Kay.
3:14
So let's test all of this out.
3:14
[SOUND] And look, there's our menu.
3:16
Cool.
3:22
So I'm gonna add an entry.
3:23
That starts a brand new thing.
3:26
Hello, this is a new entry.
3:28
Ctrl+D.
3:30
Save it, sure.
3:33
Going back to the menu, clears out the
screen again.
3:35
Let's view.
3:37
There's my new entry, and
3:39
it's nicely format, I, I've got more room,
everything's more nicely formatted.
3:40
If I got to the next entry, there's just
that entry.
3:44
If I wanna delete that one, come to there,
3:47
I'm gonna say, no, I don't wanna delete
it.
3:50
So we just moved on to the next one.
3:52
I think we'll lose our print where we
said, entry deleted, but
3:54
that's not that big of a deal.
3:58
So, yeah.
4:00
That's our app.
4:02
That's a lot better.
4:03
I did notice one thing, which if you're
typing along with me,
4:04
you're gonna get too.
4:08
[BLANK_AUDIO]
4:10
Should be enter your entry, not just enter
you entry.
4:13
All right.
4:16
That's our app, that's a whole lot better.
4:18
Wow, that's so much better.
4:20
About the only things I could see adding
to this, would be some color coding, and
4:22
maybe a bit of tech strapping.
4:25
I'll leave all of that up to you.
4:27
But I'll add a couple of handy libraries
to the teacher's notes.
4:28
Well, that's it.
4:31
We're done with another Python course,
here at Treehouse.
4:32
Based on this new ability, you should be
able to go and
4:35
improve older projects, or start brand new
ones.
4:37
Record wins and losses on the games that
we've built together.
4:40
Or, if you did the regular Expressions
course,
4:42
stick the address book entries into a
database table.
4:44
Be sure to let me know if you build
something.
4:47
I'll see you next time.
4:49
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up