what's going on everybody and welcome to
part 6 of our TV tutorial in this video
we are going to be finishing up our key
V chat application and then testing it
make sure it all works and then in the
next video will actually be packed well
we'll be going over packaging and we'll
all at least go over you know how you
would do it on Windows and how you can
do it on Android may or may not cover
iOS and other things we will see okay so
let's go ahead and get started
so basically the crux of all the things
that we have to change here are going to
be in our chat page so as soon as I find
shant page here we are so we need to
change the send message bit and then we
also want to add a couple more things
even to our init method so let's go
ahead and do that first so the first
thing we're gonna do is window we're
gonna dot bind and we're going to say on
key down equals self dot on underscore
key underscore down we will add that
method basically what that's going to be
for is so we can bind the enter key to
also send a message cool okay that way
you don't like click it you know every
chat app you hit enter and it sends a
message alright so once we've done that
now what we want to do is we are going
to clock dot schedule once and we are
going to schedule self dot focus
underscore text underscore inputs we'll
do that in one second and then we will
socket underscore client dot start on
our score listening and then self dot
incoming underscore message and show
error should there be an error okay
so now let's go ahead and handle for
that on key down time so define on
underscore key underscore down and that
will be self instance keyboard key code
text and modifiers okay
why didn't you tab over no no now you
are why okay I'm gonna let that slide
I'm gonna let that slide I'm a little
worried a little little nervous not
gonna lie
if key code is 40 that's your Enter key
self dot send underscore message and
then we'll pass none there because some
message is expecting something now now
what do we do so we could cook let's do
this send message next so rather than
printing send message as useful as that
once was we're gonna say message equals
self dot new underscore message text
that is corresponding to this write our
text input so again that's just always
able to be pulled and we are just gonna
grab whatever is in there anytime
someone hits the Enter key or clicks on
that button so either way if they hit
the enter key at run send message or if
they click on that button it runs send
message so we grab the message and then
immediately let's self dot new message
dot message dot text we're just gonna
set that to be empty because we want to
empty out once they send the message we
don't want that message to remain in
that box that would be annoying so long
as there is a message if message we're
gonna say self dot history dot update
chat history his story okay then we got
a long line here
I suppose I'll type it and we'll talk
about it so it's gonna be an F string
and then we're gonna say the color is
equal to DD 20/20 and so the our
username and then other usernames are
gonna be different colors so DD 20/20
and then we're gonna say a chat app dot
connect page dot username so this is
just and then dot text don't forget text
this is just gonna be your username
right so we're just gonna grab your
username from that original login page
then we're gonna close off our color
tags so slash color
slash and then what we're gonna do is
just do a greater than symbol there and
then whatever the message is and so
using f strings we'll just format that
in there beautiful cool so once we've
done that we want to send that message
out to everybody else so we see our
message but now we need everybody else
to see our message so we're gonna use
the socket client and we're just going
to say socket client duh send message
and it's gonna handle all the socket
stuff for us lovely now what we want to
do is refocus on that input field so
we're gonna say o'clock o'clock schedule
once Wow
self dot focus text input and we'll just
do that really quickly after they've hit
the enter key hopefully this is not like
a super fast user and we could actually
slow people down I'm I'm a totally a
person who like sends a message and then
hits enter and then continue like rather
than make all one big message I make
like four lines we could really slow
people down this way anyway but we won't
so alright once we've done that now
we're gonna need to focus text in
quit well we're gonna need that to be a
method so define focus text input
that'll be self in a non important
parameter self dot new underscore
message dot focus is equal to true so
we'll just really do that and then
finally we need to get any new messages
so we're gonna say define incoming
message self the username and the
message so self dot history dot update
chat history with an F string and again
we're gonna say color and this time
we're gonna give it a twenty D D twenty
and then it will be whatever that
username was and then slash color and
then like the for the message cool so we
will save that and I'm tempted to run
that I'm sure we are forgetting
something let's just go ahead and run it
see what happens so let's see if we have
any errors voiced of wool we'll go ahead
and connect locally because we're
running locally hello
okay so we're definitely oh wait you
know what I probably ran the old one
yeah I did
okay keep you up six cool connects great
hello okay finally oh do we
here's what I probably didn't do we gave
scrollable label and I bet on the chat
pager net I didn't change label yeah so
we need to change the self history that
needs to be a scrollable label so the
error I got just to be clear it just it
just said label has no author attribute
update chat history so that kind of
signals to me
I know what has that that's the
scrollable label and obviously it's not
a label object the scroll the label okay
so let's go ahead and just rerun that
again see what happens hello up still
crashes and label object has no
attribute update chat history well
that's kind of oh I didn't save okay
let's try again yeah okay it works okay
now we need to test to see if it updates
for other other people correctly so
let's check that really quick let me run
key be app six over again and this time
I'm going to connect to my actual server
two three one two three nine the other
thing you could do is just run to
locally but I'm gonna do it this way
hello and then
alright great cool okay so that that
works we get texts from both you know us
and the other people hopefully I don't
have any other errors here that's a lot
of code that we just kind of ran through
really quickly but yeah cool so the next
thing that we're gonna do is work on I'm
gonna have to fix that first of all but
well we'll save that for the next video
yeah we lose some of this of the
interactivity because of our fancy thing
cool
yeah the interest yeah okay fascinating
okay so we're gonna have to fix that but
we'll fix that in the next video as well
as talk about deployments or maybe I
will
yeah I think we'll fix this let's just
fix this real quick I've got that in my
notes for this video so let's go ahead
and fix that that way the next video can
be purely deployment
so update chat history layout so I would
go let's see you just think about how I
want to do this I think I'm just gonna
copy and paste these things in to fix
this because the issue is that we've
like made this like I'm pretty sure it's
this custom scrollable label update chat
history so me copy this and I'm gonna
add this here and this is all in the
text-based version of this tutorial and
if you just scroll down to the bottom
these are the fixes so basically what
we're trying to do is like when we send
the message it resized because of what
we called here so we're just gonna go
ahead and call this to occur all the
time and then the other thing I want to
do
let me grab this bit of code and we're
gonna go to the chat page init method
and I think I'll just throw it here
adjust fields and then I'm gonna put add
this to our chat page here see if we can
fix it yeah let me just rerun that
really quick and make sure that works
because this was kind of a funky a funky
issue that we were having because you
normally like you shouldn't have to deal
with that kind of stuff okay let me just
confirm yeah okay so now because the big
thing the big thing was like dependent
like wherever the app started it usually
worked out really well with the layout
but the problem is with phones you're
you want to be able to rotate the phone
so you need this chat app to constantly
change one of the interesting things
that we found doing this was
is that in adjust fields if you just
called this to run that update update
the layout that would not work we and so
we had to just schedule it once a period
it scheduled at once 0.01 seconds out so
you couldn't schedule it immediately or
you couldn't just call it you had to
schedule it to run soon not really sure
why like there's probably some back-end
thing that's happening there like maybe
things get drawn and then some logic is
done and then it's shown and then that's
what happens so and so this way we got
it to draw later I really don't know
it's kind of funky but anyways all we're
doing basically is just resizing things
so when the window gets resized we
resize things which again we wouldn't
really want to do and I'm not really
sure if there's a way around that so
anyway I'm just I'm not going to go too
deeply into that because the only reason
we have to do that I believe is purely
because of the scrollable label that we
created I'm pretty sure the other all of
the other keavy widgets you would never
have to actually do that but if you want
to make your own I guess you got to
start thinking about how to make them
also be resizable okay so now I've freed
us up so the next video I can talk
purely about deployment but if you have
any questions specifically on exactly
what we did or if this code doesn't make
any sense to you for whatever reason
it's pretty basic Python but feel free
to ask anyway yeah I think that's it
questions comments concerns whatever
feel free to leave them below otherwise
I'll see you guys in the next video
where we'll be deploying things and
actually you can even see I've got it on
my on my phone as we speak look at that
chat app incredible it's super fun
deploying to Android ok see you guys
there