1 00:00:00,300 --> 00:00:05,000 Good what you're seeing here is this creed that we created in the last lecture. 2 00:00:05,070 --> 00:00:12,960 All of this creates a window with a borough's bother and generate came about them which for now do nothing. 3 00:00:13,200 --> 00:00:17,940 But the thing here is that every time we exit this group creepy your window is created. 4 00:00:17,970 --> 00:00:25,350 But also we are creating a point to not the fall because these lines are being executed to what we want 5 00:00:25,350 --> 00:00:32,180 instead to actually execute these lines when we press generate camel bottom. 6 00:00:32,190 --> 00:00:39,130 So the first thing we have to do here is to actually wrap these lines inside of function. 7 00:00:39,330 --> 00:00:47,080 So let's say def K.M. function and here we have to pass two parameters either in file parameter and 8 00:00:47,160 --> 00:00:52,330 an old file parameter we can put some default values to these two parameters. 9 00:00:52,380 --> 00:00:59,020 So the first would be the input file and the second is the food file. 10 00:01:00,060 --> 00:01:00,720 Great. 11 00:01:00,870 --> 00:01:07,140 And of course this parameter needs to reflect the input for the receivers the fall and for the safe 12 00:01:07,140 --> 00:01:07,980 method. 13 00:01:08,310 --> 00:01:15,380 We have an error or even a valid syntax Yes we have and added the column I know to indent all these 14 00:01:15,390 --> 00:01:16,620 lines easily. 15 00:01:16,620 --> 00:01:19,720 You just go ahead to edit and indent. 16 00:01:19,860 --> 00:01:22,310 So we have four function. 17 00:01:22,500 --> 00:01:29,510 Now if I delete this file and exit the script we are just calling. 18 00:01:29,560 --> 00:01:30,300 We do. 19 00:01:30,540 --> 00:01:32,550 So the file is not generated. 20 00:01:32,700 --> 00:01:38,790 So instead we want to call this function when the generator can no bottom be suppressed for that we 21 00:01:38,790 --> 00:01:46,410 need to add a command parameter that will be equal to the name of the function that we want to execute. 22 00:01:46,730 --> 00:01:47,540 That's it. 23 00:01:47,640 --> 00:01:52,250 Now execute the script and say general. 24 00:01:53,760 --> 00:01:57,180 And we have the points for all gyrated 25 00:02:00,030 --> 00:02:02,540 And here to the points. 26 00:02:03,090 --> 00:02:04,300 Let's close this now. 27 00:02:04,320 --> 00:02:08,030 So that's how to have an action to generate Kimbell bottom. 28 00:02:08,040 --> 00:02:12,930 What we also want to do is append function to the borough Bhavan as well. 29 00:02:12,930 --> 00:02:14,950 So that was when the borough's bothered News-Press. 30 00:02:15,000 --> 00:02:20,890 They use there will be performed with a dialog window asking the user to specify those C as the file 31 00:02:20,890 --> 00:02:24,010 that they want to process to create such a dialog. 32 00:02:24,090 --> 00:02:30,100 We know you have to import the as open filename method from Khidir again. 33 00:02:30,120 --> 00:02:39,840 So from Tkinter that file dialogue import ask open file name so a file named method is part of all the 34 00:02:39,930 --> 00:02:40,830 file dialog. 35 00:02:40,830 --> 00:02:43,050 Class of the library. 36 00:02:43,170 --> 00:02:48,900 But before we use ask open file no method I would like you to see what this actually does. 37 00:02:48,930 --> 00:02:55,190 So I'm going to go ahead and or all of this line in the Python console. 38 00:02:55,350 --> 00:02:58,340 And then I create a variable and assigned to the variable. 39 00:02:58,350 --> 00:03:01,170 Then ask open file name execute. 40 00:03:01,800 --> 00:03:04,050 So we have the dialog we do. 41 00:03:04,730 --> 00:03:07,940 Now if we select a file here and say open. 42 00:03:07,980 --> 00:03:08,730 Seemingly not. 43 00:03:08,730 --> 00:03:15,390 Nothing happened but if we print out the file path variable we will get the path of the file that we 44 00:03:15,390 --> 00:03:16,030 selected. 45 00:03:16,080 --> 00:03:23,540 So with the scope of file name is doing that is juried in a string of all the files that we are specifying 46 00:03:23,580 --> 00:03:24,760 either do we window. 47 00:03:24,810 --> 00:03:30,860 So now we have to make use of that and pass that string to all Kimmo function. 48 00:03:31,020 --> 00:03:33,010 So let's go and do just that. 49 00:03:34,110 --> 00:03:41,400 And what we want to do now is to actually spend the over file name method to the Barrow's bottom that 50 00:03:41,400 --> 00:03:45,660 we have created and for that we again have to create a function. 51 00:03:45,870 --> 00:03:48,850 So let's say you've def Burrowes. 52 00:03:49,080 --> 00:03:54,440 And here we say infile equals ask open filename. 53 00:03:54,670 --> 00:03:58,900 Then we want the Broz bottom returns evolved path string. 54 00:03:59,470 --> 00:04:07,580 No we assign the borough's function to the command parameter let's execute the screaming out to see 55 00:04:07,580 --> 00:04:13,010 what's going on but I'll delete the camera for the first and execute. 56 00:04:13,250 --> 00:04:14,280 And so we have two buttons. 57 00:04:14,290 --> 00:04:16,300 So let's test the browes bottom. 58 00:04:16,370 --> 00:04:19,510 Gud looks good. 59 00:04:19,540 --> 00:04:28,480 Let me specify the file I want to convert to K.M. great and then press generate bottom and we get the 60 00:04:28,480 --> 00:04:29,050 points. 61 00:04:29,180 --> 00:04:36,350 Can fall no Everything looks beautiful but it's actually not as beautiful as it looks like it to through 62 00:04:36,360 --> 00:04:36,890 that one. 63 00:04:36,890 --> 00:04:41,040 Prezza generate came the bottom came a function is triggered. 64 00:04:41,060 --> 00:04:47,330 However if you look closely here you'll see that the Kim of function is getting the file impute from 65 00:04:47,330 --> 00:04:48,090 the string. 66 00:04:48,140 --> 00:04:49,700 But this is not what you wanted. 67 00:04:49,700 --> 00:04:56,140 What we wanted was that came a function gets a string out of a Berle's function. 68 00:04:56,750 --> 00:05:00,810 So the Berle's function is the function that generates the file path string. 69 00:05:00,860 --> 00:05:07,010 So what we want to change here is that we want to call the Burleigh's function inside the camera function 70 00:05:07,280 --> 00:05:13,780 this way very turned in fall value will be passed to the infile of peril matter here. 71 00:05:13,830 --> 00:05:14,470 Good. 72 00:05:14,770 --> 00:05:16,550 Well let's execute this now. 73 00:05:16,990 --> 00:05:17,740 Mm hmm. 74 00:05:17,930 --> 00:05:24,160 So he got an open dialog window but we didn't want it to get the dialog window immediately. 75 00:05:24,200 --> 00:05:26,640 We wanted to get it after we bought him. 76 00:05:26,690 --> 00:05:28,460 So why is this happening. 77 00:05:28,460 --> 00:05:35,360 The reason is that we're from exec you just create it from the first line and all the lines one by one 78 00:05:35,360 --> 00:05:36,440 down to the bottom. 79 00:05:36,830 --> 00:05:42,800 And when it goes to the functions it freezes the definition of the functions of a ghost of a claim of 80 00:05:42,800 --> 00:05:47,300 function and what it does here is that it exec used the browse function. 81 00:05:47,300 --> 00:05:54,380 So before we triggering the action by pressing the browser button pythoness executing the browse function 82 00:05:54,380 --> 00:05:56,440 before we pressed Broz bottom. 83 00:05:56,450 --> 00:06:03,920 So we need a way that allows us to grab the infile pass in from the Berle's function but doesn't exec 84 00:06:03,950 --> 00:06:05,540 you the Berle's function. 85 00:06:06,020 --> 00:06:10,650 So the thing that does the trick here is the global variables. 86 00:06:10,670 --> 00:06:17,240 So as I already told you a lecture about the global variables we use a global variable when we don't 87 00:06:17,240 --> 00:06:18,940 want to execute the function. 88 00:06:19,010 --> 00:06:22,900 So we just want to fetch some information on the side of that function. 89 00:06:23,010 --> 00:06:29,820 In such case we don't need the return file here but we just want to make the infile variable obal valuable. 90 00:06:30,050 --> 00:06:33,630 And of course we have to remove the argument here. 91 00:06:33,740 --> 00:06:39,470 So what happens now is that when the script is executed so it reads the definition of the browse function 92 00:06:39,530 --> 00:06:45,740 it reads the definition of a function and it doesn't call any function we need to reach to this definition. 93 00:06:45,740 --> 00:06:50,360 But before we had the brawls function been called a camel function. 94 00:06:50,360 --> 00:06:57,470 So let's take this now and I'll delete the points not the camel file or on we get. 95 00:06:57,680 --> 00:06:59,790 We know very nicely. 96 00:07:00,210 --> 00:07:09,120 I'll go to my computer which for some reason I have renamed to 7 year old who of course you know it's 97 00:07:10,280 --> 00:07:19,630 quick generate and we have a point Scammell file generated areas or African savannah growth so this 98 00:07:19,650 --> 00:07:26,720 is how you create a graphical interface and assign functions to them so that they actually do something. 99 00:07:26,730 --> 00:07:28,060 I'll see you in the next lecture.