 I again welcome to this lecture, this is the LPS course and we are continuing with looking at programming in TK tickle TK, we covered all the tickle functions and how to write tickle procedure, tickle code now we are looking into the TK functionality, we started last time last lecture we discussed some of the key elements in TK we kind of went to like some basic commands and then we also like talked about the the packer that is available that is how to pack the widgets basically, so today we will be looking more into the TK stuff let us start, so today we are going to talk about bindings essentially, so the bindings are one of the key elements in the TK, so as you know like I mean TK is a GUI programming, so all you are seeing is the graphic user interface essentially which is controlled through the cursor movements and the clicks basically, now for any click to be effective those wherever you are clicking that needs to be bound to certain scripts, so today we are going to talk about the binding as to how to bind a tickle script with user events, so here the command is bind, so the command is bind and then here we know the window .b and then we bind what is the event essentially here the event is control H essentially, so that is the event that we want to bind and then now we are binding to a script which is in this whole thing basically, so when you press the control H it translates into a tab and that is through this particular binding that we can select and then we can also use tags to select one or more windows, so in this one basically like I mean it is the window is about B the widget class is a text and all windows is all and then we have some arbitrary string basically like foo foo bar and these are all the various tags that we can apply, so now how do we specify events essentially, so the specifying events is through this the with this less than greater than and then we can also declare some modifiers which is here it is a double control meaning like you do the control key a couple of times and then essentially like there is a button press basically which is the event type actually and then you can also specify like in what kind of button or the key system that you want to do, so the other ones are basically like the number three key press a kind of things these are all like specifying various events now you can also like now do some substitutions essentially the substitutions are essentially like I mean things that you get from the event and then you are substituting into your commands, so one type of substitution is the percentage substitution the binding script, so you can get coordinates from events and the coordinates are in percentage x and percentage y and if you want to get the window that is percentage of a page w and then you can also get the character from an event which is percentage a and then there are many more which we will talk about, so here some of this one of the examples here and this is the particular window and here it is b1 motion basically and here what we do is basically it is and this is the button press basically motion we move to that xy essentially, so this is one of the events that we can say and then now for another window there is a key press basically then we insert the character that is defined by reading that the key press itself, so if you press F this is substituted with F if you press R this is our things like that so that comes out essentially and then here we say like all as you can see basically like the previous one we noted that all windows is basically like that is for all, so for all of them if you type help that goes to that opens the help window, so these are some of the examples that we can see as to how to bind scripts, so now we will be looking at this in a much more details anyway, so now the binding order essentially, so what happens when you have multiple bindings that is matching one event what takes precedence over what so these are the ones that we need to worry about in a graphical set up in a regular programming setup everything is executed one by one as you move particularly in interpreted language, so every line is executed one after the other, but in a graphical motion many events are happening at the same time, so and then these what happens when you have like the multiple bindings match one particular event, so you can have like for example here a and then you can also have like say like bind all key press, so when you press the key there this is triggered this is triggered which is triggered and how it is triggered, so so there are very various things that we can do one is we can say like it's one binding triggers per tag most specific binding this one, they are also like I mean there is a default order of tags basically which is essentially like I mean first it goes to the widget then to the class then to top level then or so this is kind of the preference how it works, so if it matches multiple bindings it looks for the widget binding first then it goes into the class then it goes to the top level then the all thing is triggered and then this can also change tags with the bind tags command, so this is another command, so we learned about bind now which is bind tags and the bind tags command actually the changes one particular tags and apply to other types of the other tags as well, so here like my button and basically like I mean we say that it's dot b foo and one all and then we can use break to skip the later tags, so again one thing is basically rules apply only to tk4.0 and later, so that's another thing that you want to keep in mind, so some more information about the bindings, some text and canals widgets support bindings internally, so they associate tags with text or graphics basically, so here like a tag add foo 1.0 2.0 or create rectangle 1c1c1c2c2c and then the tags foo and then the second thing is basically like the associate bindings with the tags okay, so another thing to notice is that the bindings always execute at the global level if binding created if the binding is created in the procedure the procedures locally available are into available at event time okay, so some more examples, so we may have to we may often want the binding script to use some information from the binding time and some from the event time, so we can use list commands to generate these scripts and use procedures to separate the event time information from the fine time information, so how do we do this, so here one typical one is essentially we say basically like bind dot x in this dot x window, we want to bind the time value and we also want to use the event time value, so when we do like I mean the we say essentially like I mean we use the the breakers or quotes this can result in the wrong values that get called essentially or that gets applied, so the correct way to do it is basically we define a procedure and then we bind the procedure set y basically as a list and then to this particular event that way we ensure that actually like I mean only go we pass this from the event into the this procedure and then the the the other expressions are actually coming from the the bind the time information no it is the bind time itself so the values are set there, so the issue with this is essentially like I mean we are only getting one value but we have like all these three different values essentially and so this is coming from the event time and this is the bind time that is happening here, so this is like I mean pass through the event essentially, so we don't have any control as to what the $B is going to be, so whatever we use whether we use like so I think like you realize that this is basically the stricter form of the specification and whereas this one allows the variable substitution, so even if you do the variable substitution in the command substitution this value is still unknown, so this is you can get it in the bind time but this event time value is still not set properly, so in order to do that we actually need to pass it into a proc and the proc is always constant on the event time which tracks the event time and then now when you pass the the bind time value into the proc here you can get the correct answer and that's what comes out as the value for Y and then you can continue that event more further down, so this is again another example of how we use the list commands, so again we use here the list so that it doesn't change basically it still treats these two as two separate items, you will see more of this kind of things in the other one other sections, now the other TK commands the so we saw like bind, pack, place things like that these are the commands that we saw for the TK, now the next command is going to be selection and then the selection essentially is to select like I mean one of the files form in a group essentially, so the selection essentially like I mean it registers a TK command to handle a selection request essentially, so in a selection essentially the the concept is basically that there is a given owner for a selection and the applications are requesting the value of the selection from that owner, so you can think of it that way essentially, so the X server itself keeps track of the ownership the applications are in form when some other application take away the ownership okay, so usually the selection get goes hand-in-hand basically the selection get essentially it returns the value of the current selection, so here selection get file name basically like returns that file name as the value essentially and if that file name does not exist basically like then this returns in error command itself returns an error, the other way to use this is essentially I mean so usually like I mean the selection get results in a string so the value that it returns the other way is to do it is basically like selection clear which clears whatever was selected before like specified selection, there is a selection handle essentially which is essentially to define whatever you can you can do a selection handle form of command essentially that command basically like I mean so that you can define that command to be the handler for the selection request, so the selection values are then passed into that that particular command then there are other ones are like the selection own command essentially which gives the part name of the window that owns that particular selection okay, so and then the other one is issuing commands to other TK applications, so here again we can send these kinds of commands essentially, so we send tgdb I can then break TK eval this is the command that we are sending it to this particular application and then we check for the the inter ps essentially using the W info command and then we will get this particular TK application what is going on this so we can use the socket to do the cross-platform applications this we saw in the previous lecture itself and also we can get the information regarding the window information the window information command is the W info and if you say like W info width of this particular window it returns what is the width of the window and then what are the children basically so what are the associated windows which are defined as part of the products or here it is the top level so you see all the ones and then it also like you can ask in specific requests as to what is the window info containing this particular location what is the window there and for accessing the other X facilities there is also like focus dot x dot y which is that generate the keyboard focus there is also like you can communicate with the window manager which is W M command essentially so title is for this window it's editing main C so when you have a window the title bar has editing main dot C and then we can also set the window manager for the geometry so this is like the top level it's 300 by 200 and then we can also like iconify that generate like those minus bus and then the exit command so if you minus it then basically go and iconify that particular window so that those features are available for this one and then for deleting the window basically like we can use the destroy command destroy dot x will destroy this one so you can have the X as basically find that thing to destroy it or something so this way you can destroy the dot window and then there is also like grab and grab release commands basically that is you can grab a particular window to do some operations and then also destroy that that that minute so now here essentially a show vars command basically this is displays values of one or more values are essentially like variables and it updates automatically so here we specify like show vars dot vars and then name age SSN and phone so it displays like the variable values and then in that window it shows like what is the name just Bob age 34 social security number and then also has a phone number so these are some of the other commands so here is the show vars procedure basically again it takes the window and then the arguments this is the top level again we named the window title as variable values as you can see here the display here and then we specify like I mean what kind of frame that we want which defines all these aspects of it on the frame element how that frame is defined and then we also specify the button is basically like I mean the same is essentially like for the menu and then we pack that on the side the top and then we specify the menu button menu file so you can see like basically like the color w is the main window the top level is the dot and then it has one child menu and then another child file and then this file is basically like we call it like this text as file and then the specify its own attribute essentially and then that has this and so if you look up here that is this this particular window here and then we also like now back the thing and then we also define here at the menu it's another stub module or the another child for this particular menu window so and then in that one we define basically like the packet to the left so from the left we pack it and then we specify basically what is the thing so as you can see here the file has been called quit so we specify the command as label is quit and the command is actually described and then so one on the line the first one that is on the line 0 0 so f is on the line so also it's also given like a shortcut basically as we can take on f to open it and those things like that so here the label quit and then we say like the destroy the whole window using the destroy command mainly so that if you say quit it completely like erases the window so again a quick look into this now we can actually add this portion of it on top of it so we see so now the next one which is the second piece of it so here again so all these things are these dot represent the previous thing so we define these things so in this one so we covered this portion and this portion in this next when we define this entire procedure so now we will go into how do we get this piece of it so for that first we need to define the variable values so which is just this much so how do we do it basically we again define the frame and then so here now we have like this one as dollar w dot menu now this portion will be called this window is called all W dot bot and then that we are packing from the bottom so we are and then title is anchor at the center is variable values and then we use like which kind of font that we want to use so and then the title is essentially like I mean we packed it the top of this particular box so now let us look at the next one so now the main thing is the show are we to display the names age social security number and the telephone for that we again describe few more the when we read the arcs essentially where the arcs are coming in and then we are going to expand that so for each of those arguments we define the frame which is the same as the argument so name so it has a name on it and then that is set to the top then that has the text of whatever the argument that is passed so for the name it is just the name and now we also assign a value which is the text variable dollar i which is it is getting it from the flow itself there is no binding law and then finally we have a name basically like that is side left side and then the value is so the way that we are assigning basically now is name and value so we put the name first and then the value okay so here the name refers to the dollar i dot name and then the dollar value is dollar i dot value which is basically in this case it is bought and then this we do it for all the arguments that is specified through the show or command so essentially like I mean it does it for me and then it does it for agents age and then assistant and then finally so I hope like I mean this example was so clear enough how we can get to this point once again so simple start with the show wars essentially like I mean this is going to the dot wars window and then we want to display name age social security number and phone number so we start by specifying the top level window the top level window is nothing but essentially it has variable values as a panel and then in the frame we specify how the frame is being made and then where do we put the text essentially and then we also create another one another child window which is the menu essentially yeah so that menu again it becomes a button essentially and then it has then text as file and then we create another child window underneath it which is called quit which essentially gets this window out now once we define the top level stuff then now we have to define the all the remaining stuff for that we build the window into two separate things basically so we build first the variable values and then we can populate this from the flow itself so this is something that we saw here in this one so basically the event time versus bind time so in order to do that what we need to do is first we define this particular window which is also not very challenging we define another child window called the what w dot what and then we define its attributes what kind of button it has basically and then what is the text that goes into that once you do that then we populate the remaining stuff which is the what is the name what is the age what is your certificate the number and phone number and for that we just use a for each command to generate for each one of them like for name for age for SSN and form and the types that we want to build are basically again we need to do another child window the child window will be like just the name alone then the age then SSN then form in the name one we define two variables one is this name so which is just prints whatever is assigned here and then this one gets to the event modification so I think like this is one example I also want you to actually practice this more so that you can understand the concepts more better so once you start writing the ticket code then you will be fine you should be able to figure out all of these event driven things one of the key aspects of any windows drastically user interface kind of things is this event driven mode essentially so everything is an event when you move the mouse it's an event and how do you capture and how do you react to it that's what I know so now the second example that we will look into is so the making a dialogue box essentially so a dialogue box is mainly like a window like this there it pops up during some program execution it asks you for a separate several one question it asks you one question and it has separate several choices and then you can click one of them and then that particular thing is executed so in the ticket terms we can say that basically so make dialogue is the command name and then so the D is the window man window sorry dot D is the window name and now we have a title which is called file modified and then what kind of message is this so we tap it as like dollar message so warning and then we also have the button labels so each one will generate one button here changes and so how does this work essentially so at the high level this is the command that make dialogue but underneath that what do you have to write this basically it's the procedure make dialogue and it has these different things essentially this is the window itself it's title the text the bitmap and then the various arguments so we define the top level as W $ W and then we assign the title title to this particular window then we also create some window manager protocol basically which is just say basically like how do we delete this particular and then we define a child window which is the $ W dot top and then this child window and then we also the child window is actually look for this top is packed at the top level the top most point and then we also have a similar one for the bottom side which is again another child window W dot bot and that goes into the bottom and now we can also specify some label the label is essentially the text that we grab so here the text is like that you have modified the file food article and do you wish to save your school so simple command but it takes a while before we can so now once we finish basically this packing basically the first one now what we do so if you don't provide any bitmap actually like when you when you provide the bitmap when bitmap is not null then it adds that bitmap essentially so we have a new window called bitmap and then we pack it towards the left side and then it is packed on the left it is the 3 millimeter by why is too many so that's how this text is being displayed here once we finish this then now we need to put the last bit which is the bottom window so for that the command is basically set i equal to 0 for each button in the set of arguments we create the button essentially as a child process to the main one and then we call the button as the dollar but essentially as the same text format that we call and then we also assign the command set button $W $I so once we do that then we need to pack basically this one and the way that we pack is essentially one two three this way and then we go into the next next and grab the next button and then finally we use the button so here if you notice basically the buttons are a safe file this card changes all the time so we do the we grab the global I mean actually like we define this flow button $W and then we grab the window manager set old focus just focus and then we do this focus for the window and then we just variable we get we do it pick a weight variable button and $W and then we destroy that window and then focus if the is another come a focus command is for the old focus and then we just return the evaluation with the button okay so in summary creating interfaces in TK is an easy way basically we can create widgets we can arrange with the geometry managers connect to applications and to each other so these are all some of the key benefits of TK and then always it means better basically to have a single speaking language that you can use for variety of things so whether in to specify a user interface whether you want to or some widgets to invoke an application the widgets basically to communicate with each other for communicating with outside world is another one and then for changing anything dynamic in summary yeah so in summary we saw like a couple of programs before that we started with the key bindings essentially bindings as one of the key aspects of of TK so and then the bindings essentially we actually bind commands and so various events using the bind command so why is this useful essentially this is the way that we can execute commands when user presses the any kind of keys or any interaction that the user has we can immediately do bind that event to a particular command and then and then we went into like I mean specifying what kind of specific events are there and we also understood how to do substitutions within the binding and then what is the order of the bindings because multiple events can happen or even can actually trigger multiple bindings now which binding gets the priority of the presence that is the key thing and then one way to do that is essentially to so it goes in the default order of go back essentially there is widget followed by class followed by top level and then followed by all so there is a hierarchy there and that we need to keep in mind and then essentially like I mean we have like text and also like the canvas widgets that are support that support bindings internally so here is a text one basically which is like the tag is already specifying internal bindings and then for creating a rectangle we need basically the length with height actually like length and width of the rectangle so that is again through this command we can specify now we have like two concepts basically there is a binding time and event time and how do we do this essentially because any script would want some information from the bind time meaning if you are interactively selecting and then something from the event time driven through the time so how do we do that how do we select those things we cannot use a single modifier like we taught we learned in tickle programming which is like the curly braces or the quotes the quotes is the soft matching or basically it tries to replace all the variables and the command names whereas the other one does not do it but we cannot use both of them so we going to intermediate form where we use list to actually separate these items and not having to collide with each other so once you have that list essentially like what is specified here what we need to specify inside is based on how deep you want to go essentially and then essentially with here the set why the proc which now keeps track of the the the binding time information only like I mean we pass this dollar a into that particular procedure and that is an event event even more and then now you get the results and then you can compare essentially and then we also saw some other TK commands like selection get is one of them and then which is essentially gives a label event basically like in memory and then when you want to issue commands to other TK applications basically we said these two parents and then run the command and then it should be fine and then we can also like get windows information that is W in for weight, W in for children, W in for content and so I think like that and then we can also access the keyboard focus using the focus commands so so the focus command essentially so they are part of the the dialogue boxes themselves essentially and then so the top-level window essentially has the input focus essentially and then you can require the focus to change from one to the other so or you can specify the keyboard to be the focus which is using the power x or the syntax and then we can also communicate with other window communicate with your own window manager using the WM command which is stands for Windows Manager and then we can destroy any window using destroy dot x and then there are some add this into then we looked at a couple of examples the first example being the show wars example as to how to write this so show wars is essentially there's a procedure and so as with any other procedure the show wars has the variables essentially and then the arguments I'm sorry the dot wars is the window and then the arguments so this is the window so in this window how do we specify in this again so we are building whole program here so we call this as the show wars procedure which has the window and then the whole bunch of arguments again here you can see that actually this is left as infinite list and then now we set the top level to be the name of the window then we put then the title as variable values then we generate new windows from the original one and here like I mean it's called menu and using the frame command so this is this is a child one and then we can see what I mean we can show what is the text for this one and then what are the menus essentially and now the the menu itself can have additional child for example if you want to define with which destroy the whole window you can put it there and then we also continued with that and then looked at the remains of the program essentially so here we generate another child window all the dot bot and then in the dot bot we can actually specify the variable values yes it is not done there is one more part which is now we have to show all the various pieces of it basically what is the use the specified ones and then for each one of them we need to now go and find out from the event mode what is the value of the various variables and then substitute those values in the main output and then you are done so here we specify like two items so so for each one in the menu basically we define a new windows and then we say like how to packet and what to anchor on and then basically these are all in terms of like the name value test so the bottom ones are all like name value there so that once we fetch the name we know the body so that was one one quick example and then the other example was the make dialogue box which is again specified as make dialogue dot d then file modified the message warning and then we say file discard finger from the editor so the when this dialogue box opens basically we will see that there is some message here and then it has these three buttons say file discarding this and return to editor and then essentially like so how to build it is again we have the input it is already specified and then we define the top level top level window and then we define a tile for it then we can do like delete any kind of window basically like which is embedded thing already there and then that is pretty much it so once we have this form this this window covered then essentially like now what we need to do is we need to bring up the various buttons as bitmaps so here again like I mean we are passing that bitmap basically which is and then it is to pack those things in then we want to also generate on each of the arguments we need to generate a button so we know that the arguments are safe file discard changes and return to editor so for that we need to put some file for that and now the last one essentially which is what kind of things it will say so we basically we grab the window and then we set the old focus to the new focus and then focus we change to the top level window and then we wait with the variable and for the button press and then in that case like then we destroy the W and then say the old focus and then we go back to where we come from so in summary essentially like I mean creating interfaces with the tk is very easy it creates widgets and then we can arrange with the geography geometry manager and then we can connect to applications on both of each other so I think I am going to stop at this point we will continue from this in the next lecture.