Build a Language Translator App - Python Tkinter GUI Tutorial 200

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys john here from godaddy.com and in this video we're going to build this translation app for kinter in python all right guys like i said in this video we're going to make this translation app but before we get started if you like this video you want to see more like it be sure to smash like button below subscribe to the channel give me a thumbs up the youtube algorithm and check out codingme.com wrote dozens of courses with hundreds of videos to teach you to code use coupon code youtube wanting to get 30 off memberships all my courses videos and books run time fee is just 49 which is insanely cheap all right like i said in this video we're going to build this cool little translation app so you know we can type something in here click translate and you can see we can pick from english to all these other ones i hear i've got french selected but you know german greek there's a whole list we've got a whole lot of different languages to choose from and very very cool so this is the 200th episode of this kinder playlist can you believe this 200 of these crazy videos we've made so far we're going to keep going i guess but man 200 so i thought this would be a fun little app to build on our 200th video pretty interesting and you know a nice little app to uh hit 200 on and just a reminder my cyber monday sale from yesterday all my udemy courses at as low as they'll let me discount just go to dot com forward slash udemy and you can see all the courses listed there if you click on any of them you'll get the discount automatically at checkout it's the lowest price udemy lets me discount courses you know they're in charge of setting how much i can discount each course over there but go check those out if there's a course you're interested in that would be a great time to pick it up at a cheap price and you know for the next day or two those will be up at discounted prices so all right let's take a look at this here we've got a text box here and a text box here we've got a button in the middle we've got some combo drop down boxes and a clear button here there's not much to this app as far as that goes all the cool stuff is going to be behind the scenes where we find the list of all of the languages and then when we actually translate from one to the other so so head back over to recode i'm using the spline text editor and the get bash terminal as always and as always you can find a link to the code in the pin comment section below as well as a link to the kinter playlist with now 200 videos man 200 so check that out if you haven't seen it so far so i've got a file called translate.pi it's just our basic kinder starter code that we always have and we need to install a couple of libraries in order to make this work so let's head over to our terminal i'm in my see gui directory i've got my virtual environment turned on you can or can't have that on it doesn't matter i've just got it turned on because we're going to be installing new things and i like to do that in a virtual environment but you absolutely don't have to so the first thing we want to do is pip install google trans and google trans is basically we're going to use this to get the list of languages so you don't need this if you've already got that list of languages you could do that but this makes it very easy and you'll see why going forward in this video we also need to pip install text blob and the text blob library is very cool it lets you do all kinds of neat things with text and nlp stuff and categorization and and translation so we're going to use that for that so pip install text blob i've already got it so it says hey you've already got it okay so let's head back over to our code and start building this thing out so the first thing we need to do is import google trans and we also want to import text blob and we're also going to be using a ttk combo drop down because it looks nicer and also probably a message box that we could pop up a little message in case there's an error so we need to import those two so let's go from tkinter import ttk and message box and if you don't know what either of those are i've got 200 other videos in the playlist that talk about these in great detail so okay we got that stuff so now let's build out the gui let's create our text boxes so i'm going to call the first one original text and that's going to be a text box we want to put it in root let's give this a height of 10 and a width of like 40. i've already kind of played around with this so i know the sizes that i want but make them any size you want and then we can go original text now i want to grid these so dot grid want to put this in row 0 and column 0 and i also want to give this a pad y of 20 just to push it down the screen a little bit and also a pad x of like 10 to push it from the you know the side of the app a little bit so okay that looks good i'm going to go ahead and copy this and we'll call the second one [Music] translated text so the first one is the original text the second one will be the translated text we want to put this in column two i think yeah so the first one will be in column zero then there'll be a space and then column two for the next one and that looks good now let's also create a button so i'm gonna call this the translate underscore button put this right in the middle so that's gonna be a button we wanna put it in root we want the text to equal translate all right and let's give this a font of helvetica with a size of like 24 and we finally want to give this a command of translate it alright no exclamation point so we'll create this function in just a second here so now let's add this button so translate button dot grid we want to put this into row 0 column 1 and let's also give this a pad x of like 10 to space it apart a little bit so okay that looks good let's go ahead and save this and run just to make sure that looks okay head back over here and let's go python translate dot by oh translate it not found oh that function all right well let's come up here and create our translate it function and for now let's just pass save this head back over here run this guy again okay so that looks pretty good i like the spacing here we've got some padding here and some padding here and head in between them okay that looks good now we want some combo boxes underneath these text boxes now you could also put scroll bars in these text boxes i'll leave that to you i've done that many times in many other videos in the playlist so you can check that out if you want to learn how to do that for now i'm just going to leave off the scroll bars because it's going to take a long time and this app is already going to take us a little while to make so we'll just leave it at that so let's come back over here and let's create combo boxes so i'm going to call my first one original underscore combo and that's going to be a ttk dot combo box and we want to put it in root we want the width to equal 50 and the value to equal something what do we want the value to equal well let's have it equal language underscore list now we don't have this variable yet we'll create it in a little bit we'll use that google trans to get that list of languages and we'll put it into the list like that so all right that looks good now i want to set one to be the default one that shows up so let's go original combo dot current and i want that to be the 21st one which i happen to know is english you wouldn't know that unless you looked at the list and we'll look at the lesson a bit but i already know it's going to be the 21st one so i'm going to put that put whatever default language you want to show up as the default language like that and it's just like any python list it starts at zero one two three four so just go through the list count up and then put your number in and then finally let's go original underscore combo dot grid we're gonna put this in row equals one so underneath that text box and column equals zero so i'm just going to go ahead and copy this guy and paste it in a second time and this one will be we'll call this translated combo same thing here same thing here we want this to be row two and then for this current one i i you know it really doesn't matter what default one you put i'm gonna put 26 that's the french language so that'll just be french so okay that looks good now finally we need a clear button so let's go clear button clear the screen so clear underscore button that's going to be a button we want to put it in root we want the text to equal clear and we want the command to equal clear and we'll create that command in just a second now let's clear underscore button dot grid this guy and we want to put this in row two i want to push it down even further and then let's put it in column one so it's right in the middle so okay that looks good let's come up here and create that uh clear function just while i am thinking about it and this is simple so we'll just knock this out so let's uh clear the text boxes right so that's just gonna be the original underscore text dot delete and we want to delete from position 1.0 all the way to end remember that's how we delete things from a text box so we put this in again and go translated underscore text same deal so okay let's go and save this and run it make sure that looks okay we did that pretty quick and oh there's always an error language list is not defined yes of course not so let's very quickly let's say what right here set language underscore list two one two three four whatever okay just a little something to put in there for now so let's run this guy again uh oh index 21 is out of range ah of course it is well let's go five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty two three four five seven whatever unsave this run it again all right okay so that does not look correct let's fix that real quick it's a 200th video it wouldn't be us if we didn't make a mistake so this is going to be let's see row two column two zero one two okay this is gonna be row one though alrighty that should work let's run this guy again all right so that looks good if we type stuff in here and type stuff in there and click the clear button those both disappear we've got drop down boxes with lots of numbers in them we'll fix that in a second all right looking good so far so now we need to do the heavy lifting we need to actually build out this functionality so let's get rid of this guy now let's grab language list from google trans this is going to take us several steps here so let's create a variable called languages and this is going to be a google trans dot languages right actually let me bring back the language list thing there we go we'll delete that in a second but now if we want to print languages just to see what the heck this is we can do that save this run it go ahead and close it immediately and when we do boom this is the list of languages and you'll notice it's a dictionary so we have sort of a language code and then the name itself so la latin right sk slovak right so we're going to need both of these things so we've got all this stuff how do we parse this apart and add it to our drop down combo box well we can do that get rid of this guy so let's create that variable again called language language list and we can just call the list function in python and then pass in our languages dot values right and if we want to now print out the language list in fact we can probably maybe get rid of that let's save this and run and see what that looks like clear the screen first run this guy close it right away boom now we get something a little bit better right this is now a python list and it just has the names themselves the code isn't there the sk for slovak right it just says slovak so okay that's good to go right so let's run this guy again and we can see boom there's our language list now these are all lowercase if you wanted to transfer them to uppercase using python you could do that i'm just going to leave them lowercase but okay that looks pretty good so far so now let's go ahead and get rid of that let's say convert to list whatever so now let's head up to our translated function and here we want to actually you know translate something so i'm going to create a try block i want to do this inside of a try block why because we're translating things and you know you might enter something that can't be translated so error message is going to pop up or we may not be able to connect to something and the error message will pop up so we're going to do it like this with a try block and then i'm just going to come right down here and say accept exception as e and when that happens let's throw up a message box so message message box dot show error and here let's put a title of trans later and then let's just put the error out onto the screen so yeah that looks good so now inside of here what do we want to do well remember that very first thing we created at languages google trans.languages it had two things it had the code and the language so sk and slovak en in english fr and france we need to get those codes and we're going to use those to sort of translate the thing right so we need to get them so we do that several different ways let's get the languages from the dictionary keys right so let's uh get the from language key and we also want to get the to language key right so the original is the from we're translating it from one language to another language so we need the keys for the from and the two so if we picked english we need en if we picked france to translate it too we need fr so we need to get those things so we can do that so let's go for key and value in languages dot items all right and now let's do an if statement so let's say if the value [Music] equals the original underscore combo dot get so the original underscore combo is the drop down box so in a dictionary you have a key value pair the key is the two digit code so en the value is english so key value so we're saying if the value is the same as in the drop down box that's the thing we want then we need to get its key so if we look through the dictionary and we see english and that's the one that's in our combo box we're going to say hey get the key for that right so to do that we can just say let's create a variable i'm going to call it from language underscore key and set that equal to the key which is just this guy right so that'll do that now we can do the same thing down here for this guy to get the two language thing but instead of the original combo box we're gonna look in the translated combo box right instead of calling it from language key let's call it the two language key right okay so we've got our two keys so in our case english en french fr right okay pretty simple so now let's create a variable i'm going to call it words right and here's where we're going to use the text blob remember we imported this text blob thing and if you want to look up the documentation for text blob just google python text blob the documentation is fantastic you could do so much with this thing i definitely suggest you go check that out so we'll get into that maybe in another video but in this video we're just going to set this up we're going to use it we're going to call we're going to create a text blob dot text blob function and inside of here we're going to say what text do we want what text do we want to translate well we want the original text right that is the original underscore text dot get that's the text box remember to get anything from a text box we have to designate the coordinates in the text box we want to get everything from position 1.0 to end that will grab everything in that original text box right and we're going to turn it into a text blob function and we're going to assign it to the variable words so now maybe i should probably comment this turn original text into a text blob so now all we need to do is translate this guy so translate text right so we can take words and set that equal to words dot translate and you want to spell translate right translate there we go and now we just say the from underscore language set that equal to something and then the two language and set that equal to something well what do we want what's the from language well that's our from language key en in this case what's the two language it's our two language key all right there we go piece of cake right now it's been translated now we just need to output translated text to screen and remember that other text box we called translated underscore text and we want a dot insert at position 1.0 and what do we want to stick in there what do we want to insert those words right boom that's all there is to it now this translated text if we've already translated something there's already going to be text in that box so we probably want to delete that whenever this whole thing starts so let's come up here and say translated text dot delete from 1.0 to end right and we could say delete any previous trans okay let's go and save this and run it there is almost certainly going to be an error because man we flew right through that so let's run this guy so we can say hello translate it uh oh name translated combo is not defined translated uh i misspelled translation again but you notice we have a nice little pop-up box because that error handling that try block remember that's cool so i'm just going to search for translated there we go translate there we go and let's try it again just in case man i misspelled translator all over the place didn't i that's like okay there we go one more nope all right so go ahead and save this run it one more time it's a 200th video we must have 200 errors that's how that works so hello salute well that's not correct without the exclamation point bonjour all right how are you comment sava i don't know oh and we could play around so we don't want don't want french let's try german how are you v gate s einen okay my name is john elder period my name is john elder okay so very cool and again we can pick you know we can hear we could try it the other way let's put german in here i don't know it's a 200th video man let's play around with this thing and we could change this back to what english translate it my name is john elder hey look at that it worked so very cool and very easy and like i said you can head over to google and just type in python text blob and get the documentation and you can see there is all kinds of text processing cool stuff you can do with this nlp natural language processing you know you can classification tokenization word and phrase frequency which is very cool parsing engrams word inflections spelling correction all kinds of stuff you could do with this you can see there's a pretty good set of documentation here blob classes very well written very well done this is great i definitely recommend you play around with this but uh just that easy we've got our own little translator so you don't have to head over to google translate every time you want to translate something just pull up your little app and pretty cool so before we go i just want to thank everybody for sticking with me for 200 kinder videos i can hardly believe it it's been a good couple of years coming but man 200 videos i'm kind of speechless i don't know we're just going to keep cranking them out because this is fun so i don't know you guys seem to like them so we'll keep doing them and uh that's all there is to it so that's all for this video if you like to be sure to smash the like button below subscribe to the channel give me a thumbs up for the youtube algorithm and check out kodamy.com where you can use coupon code youtube wanting to get 30 off memberships your page is 49 to access all my courses over 47 courses hundreds of videos in the pds of all my best-selling coding books join over 150 000 students learning to code just like you my name is john elder from codinbue.com and i'll see you in the next video
Info
Channel: Codemy.com
Views: 1,931
Rating: undefined out of 5
Keywords: tkinter language translator, tkinter translator, tkinter translate, translate with tkinter, python translator program, language translator using python, language translator app using python, google translator python, python googletrans, python textblob, python textblob translate, python textblob transloator, codemy.com, tkinter.com, john elder, john elder tkinter, john elder tkinter tutorial, john elder tkinter tutorial #200, tkinter tutorial #200, google translate
Id: 64f5fKBM3-o
Channel Id: undefined
Length: 21min 26sec (1286 seconds)
Published: Tue Nov 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.