what's going on everybody and welcome to
part 2 of the TV cross-platform GUI
development tutorial series in this
video we're going to be doing is
continue along we're trying to make this
chat application and the first thing we
need to be able to do is fill out that
form and then like submit the form right
so we need a button to click probably
says join or something like that and
then besides just throw it in the button
we also need to handle for the event
when that button is clicked so we're
tapped or whatever so that's what we
gonna be doing today is buttons events
and just so quality of life update
immediately out the gate so let's go
ahead and get started so we've got these
these things all added already now the
first thing that we're gonna do is throw
in a button so we're gonna say from Q V
dot u IX top button we're going to
import button now we want to use that
button so again all the widgets are
placed in order so we can just like
throw in a button right so we could say
self dot join equals button and then we
could say that text here is join okay
and then we could say self dot add a
widget self dot joint oops don't run it
there cool so I'll save that and let's
just run that real quick kind of went
off screen but anyway there you go IP
ports username and then there's a join
button doesn't do anything when we click
it though now I kind of want the join
button over here so this is actually
really simple there's like there's a
million things that we could do to get
this button to be moved and to place
things specifically especially if you
want to start getting fancy with layouts
inside of layouts and you know you could
get really cool with this you could just
have like a grid layout for row or yeah
for rows and then each row is its own
two column layout and then you got bang
bang bang bang and then join could be
the whole thing down here right so yeah
you can get super fancy or you could
just self dot add widgets and an empty
label but so once I do that run that so
we're adding that before we add the
widget
the button and boom we got the button
oriented over to the right that's good
enough for me but like I said if you
want to fix it and do it a different way
have at it so that's buttons okay but
obviously we want these buttons to do
stuff when they're clicked so what we
want to do is bind a function to the
button so that's pretty easy actually so
what we're gonna say is self dot join
dot bind that's just an attribute
basically or a method of this button
that we can run and then we're gonna
bind what well we're gonna say on press
there's there's probably all kinds this
is the only method I've ever used but I
would wager maybe if you hovered over it
or maybe on a on hold or something you
might have a thing I don't know anyway
there's probably methods like that you
could just assume they exist so check
those out in the API documentation on
press what do we want to do self dot
join button seems to make sense right so
we're gonna run a method called join
button now that method doesn't quite yet
exist so we better probably make it so
what we're gonna do is define and just
so it's clear we're in the class Connect
page we were coding in the init method
now we're just making another method so
to fine join button method and self and
when you click on the button it's also
going to pass or when you bind I don't
know anyway it's gonna pass instance
we're gonna handle for that so we're
gonna also take an instance so here
we're gonna get we can grab really
whatever we want right because if
someone's filled out these forums like
it's a it's a live instance right so as
people are putting text inside of these
fields we can actually grab that and
then do something with it so not only so
just like later on down the road we're
gonna talk about scheduling things and
just running things so just understand
that everything's running like live as
you put things in it just so happens
that we're like scheduling things and it
seems very script e as we click buttons
or whatever but it doesn't have to be
like that so just keep that in mind but
anyway so this event here we're running
the event now let's just grab some stuff
real quick we're just gonna say port
equals self
self dot port dot txt we're gonna say IP
equals self dot IP dot text and then
username equals self dot username dot
txt so we're just grabbing the text
values of those fields at the time of
the button press but again like I said
you can grab values of fields at any
point you can have all kinds of reasons
why you might grab that stuff so anyway
port IP username and then for now let's
just say print F actually let's say
attempting to join IP : port as username
okay
so let's save that and did I close I
guess I closed my console window awesome
I love it when that happens
uh let's just run that again seven I
forget what I call this key V app - okay
run that let's not close the console
until next time yeah okay so IP let's
just I'm just gonna throw in some stuff
really quick and talk about that I hit
join and I shall bring this back
so we're attempting to join this : this
as this way I want both one two three
four oh oh how about hot I don't know
something hinky going on there there we
go okay cool so I want to bring this
down here I'm gonna close this so one
thing right out of the gate it's very
tedious to keep filling out the IP the
port the username Jesus are we're gonna
keep going at the same one every single
time so so both in development and then
in actual use case we probably actually
just wanted to like save these things so
I'm just gonna make that final quality
of life update for us real quick and so
the first thing we're going to do is
basically right here we're just gonna
say with open preheat ales text with the
intention to write as f we're gonna say
f dot right and we're just going to
write basically this with some com
so I'm just gonna copy pasta cama cama
cool okay
so we'll save that fix this for Pepe and
awesome so with that now what we want to
do is we're gonna import import OS and
then somewhere in this init method we're
going to get the initial values for IP
port and user names so the first thing
we need to know is if that file exists
because if this has never actually been
run that file won't exist so if OS dot
paths dot is file preheat ailes dot txt
if that's the case with open this file
with the intention to read as F we're
going to say the details of that file
are let's see if we're gonna say D
equals F dot read and then we'll
actually just go ahead and split by
comma and then what was it yeah IP port
username so we'll just say pre VIP
equals D zero and then just take this
and then we'll paste that twice one two
IP poor user nombre if that's the case
do that otherwise we need to handle if
it doesn't so we'll paste that in come
on me okay oops
knocking stuff over okay and then what
we want to do is add in the starting
text so so in text input we can also
pass a metric or a parameter it called
text so in this case would be pre by P
so now what I'm going to do is just take
this copy
and then I'm gonna paste here and paste
here now this would be pre port and then
this will be proved username cool okay
that should be everything so let me go
ahead and save that
let me just rerun this and oh because it
maybe because I had the file already so
I've already done this um yeah just like
loaded it I'm gonna delete those real
quick and just test to make sure
everything's working the way I have it
now just rerun that up so good thing oh
right duh
okay this should be empty I'm glad I
tested that uh so make these empty so if
the file doesn't exist we can't split
anything and D doesn't exist either so
nice good work everybody
basic Python skills all right so now it
is empty and yeah I'm just gonna fill
out what I had before so one 27001 port
1 2 3 4 is fine for now and Centex we
hit join and sure enough attempting to
join I'll close that and then we'll we
run that one more time
and sure enough everything's there
already for us so I don't have to keep
retyping it so the IP and port might
change depending on what you guys plan
to use for the server or the socket
space basically the socket server I'm
probably gonna host mine and I'm gonna
work off with that but I'm gonna take
that down before I release these videos
because there's probably all kinds of
security issues that could happen so cuz
one we're passing through key v2 we did
very little security checks for the
socket based tutorial bit so that seems
pretty risky to let that run live and
let you guys use it so I'm just gonna
have you guys probably run it locally on
a local port or something like that but
you know we'll see ok so that's it for
now quick shout out to my most recent
channel members Ivan Dixon and Matthew
you guys are awesome thank you very much
for your support
if you don't know
you can join by clicking that beautiful
beautiful blue button that just beckons
your click okay so in the next video
what we're talking about is what happens
once we click join so yeah we're like
handling the event but you actually
probably want to actually do something I
don't know useful so we need to like
change the screen like once we click
join we don't even we don't want this
layout anymore we don't really want the
screen anymore we want the chat screen
thing yeah so how do we do that
so that's what we're gonna be talking
about in the next video questions
comments concerns whatever feel free to
leave them below also join the discord
discord GG slash Centex that's it
everybody see you next time