hi guys welcome back to psus YouTube channel with curiosity me for Cod today we'll be discussing about how to create a automatic code generator GUI using seing but before that we'll be checking the packages pre-installed in my system so the First Command that I'm going to execute in command prompt is PIP list where you can see all the packages with the versions so it can give a look about what package is what version and update it accordingly so you can take a look onto your packages if not installed please do install it you can just Google how to install and there'll be a command for that to execute in command prompt another command to check for all these is PIP freeze which gives a similar output where packages with the version will be mentioned so let's get started with the coding part so as usual we are going to start with importing the necessary libraries which includes te as TK which is usually a python standard GUI package and from T we have import ttk which provides team vets for T and we have having from P image and image TK these modules are used for image processing in tein Moving On we have first function has generate code snippet and if you go down we have another function called as generate code and which we have another called create gradient image and then we have the GUI part down so let's go on and see what each function does let me just select the entire function so firstly we are having DF generate code snippit and language as a variable to pass through this line defines a function name generate Cod snippet that takes a language parameter this function generates a Cod snippit based on the provided language and we have Cod snippet is equal to this line initializes a dictionary named code Snippets that would hold code Snippets for various programming languages so for example we have given Python and we have given the code for Python and if name is equal to every like the entire programming language the code of the snippet part is given here for Python and if you go down we have uh for various languages which includes see SS you can see we have write your CSS code here and we have SQL write your SQL code here with like the formula and we have Ruby write your Ruby code here and we have Swift also and we have PHP how PHP starts the program and we have C hash C hash is C++ we start the program by using system class program static vo Main and what are the like snippet part and we have R language also so how do you start R language and we have go language which is package mean uh import fmt function Main and all the snippet part is given here we also have pear language and uh cotl language is also there and we have scale language and typescript and Lua has skill language is also there matlb is also there dot it's there and if you go down we have assembly rust also is there and Objective C is also there for object C you can say import the foundation foundation. H and if you go down we have int main int a r GC constru car into AR and we have write your Objective C code here to and then return zero is an obvious part of the object to see and then we have another language called as Julia then we have vbet and so many languages have included you can add and we have the return cod. getet language language not supported if any other language is there we the message of language not supported is given so let's move on to the next function function is to generate the code so here you can see without any parameters this function generat on the selected language now this is for selecting the language we have language is equal to language combo.
getet and we have the from the drop down menu and assign the variable language and we have Cod this line calls to generate code snippet function with the selected language and assigns the return code snippet to the variable code snippit and we have code t. m this Line clears any existing from the the row of 1. 0 to the end of tk.
n we have then code text insert tk. n Cod spp it this line insert support at the end of the text and uh we'll move on to the next function so the next function is to create the gradient image with the parameters width height start color and end color this line defines a function name create gradient image with parameter withd height start color and end color this function generates a gradient image which with the specified Dimension and colors and we have gradient is equal to image. new RGB width height and start color this line creates a new RGB Image image.
new with the specified withd height start color and image. new function from the P which is python image Library module and we have a for Loop so for why in the range height this line starts a loop for iterating over each pixel Row in the image from zero to the height minus one and we have given R is equal to in start color Z the formulas of RGB are been given these L calculate the inter plotted color values of RGB of each pixel low and the gradient based on the start and the end colors positioning by with the height image and we have gradient do based RGB 0a y with comma y + 1 this line face a horizontal line of color RGB on the gradient image of the current row Y and we have written image tk. photo image gradient this line returns a photo image object created by the gradient image photo image in the class from the image TK module which is used for displaying in the dinder part so moving on to the GUI part we have the entire GUI part listed down here so you can see we have started with root equal tkk this line creates the main window of the application using tk.
TK it initializes an instance of TK class which represents the main window and we have root. title automatic code generator this line sets the title of the main window to automatic code generator and we have root geometry 600 to 400 this line sets the initial size of the main window to 600 pixel white and 400 pixel high and we have gradient color start 255 255 white that is we are starting with the color of white and gradient and color 0 128 128 this end color is p so these line defines the start and end colors of the gradient background of the application window and the colors are represented by RGB tles and you have gr gradient image is equal to create gradient image 600 400 gradient starting and ending color this line calls to create gradient image function to generate a gradient image with specify Dimension and colors and assigns the result to the variable grate image and we have background label is equal to tk. label root comma image is equal to gradient image this line creates a label wiget name background label with the gradient image as it backround and we have background label dot place we have uh Rel is equal to Z relay r y is equal to Z width and height is equal to 111 this line places the background label widget in the main window with its relevant position and size specified as covering the entire window and if you come down we have language label is equal to tk.
tk. label root text is equal to select programming language background is equal to background label CJ background this line creates a label widget called as language label with the text select the programming language the background color in the label is such set to match the background color of the background label widget and we have language. label.
grid row Z column z p x is 10 and P Y is five and sck is equal to W this line uses the G geometry manager to place the language language language label diget in the first and the First Column of the window GD it also sets padding which is pad X and Pad around the widget and specifies sticky behavior of West W which is West meaning the widget will be left aligned within its grid cell and we have languages listed in the drop down as all the languages program whatever we have given above we have python Java all the programs language whichever code snippet is given everything is mentioned here and we have language combo is equal to TK do TK combox root value labels with is 20 this line generates a combox widget with the available program language as values the wi the combox is set of 20 characters and we have language combo. grid row is equal to0 column 1 P xal 10 p y isal 5 these lines are used the grid geometry manager to place the language comma widget in the first row and select common column of the window grid padding pad X and Pad Y is added around the widget and we have generate button isal TK do button root text is generate code and command is equal to generate code this line creates a button widget which is generate button with the text generate code when clicked the button executes the generate code function and we have generate button. grid row is equal to zero column equal 0 p x = 10 p y is equal to 5 this line uses the grid geometry man maner to place the generate button widget in the first row and third column of the window grid padding which is p x and P Y is added around the widget and we have code label is equal to TK do dk.
label root text is generate Co snippet background is equal to background label C get background so this line creates a label widget code label with the text generate code snippet the background color of the label is set to match the background color of the background label widget and we have code label grid row is equal to one column zero pad X is 10 pad Y is f and sticky W this line is used the GD geometry manager to place the code label widget in the second row and the First Column of the window grid padding pad X and Pad Y is added around the and sticky behavior is set to W which is red we have Cod text equal to tk. text root width is equal to height is equal to 15 this line creates a text wiget with with a width of 60 characters and height of 15 lines and then we have code text. grit row is equal to two column is equal to zero columns span is three pad X is 10 p y is five this line uses the grid geometry manager place the cortext within the third row panning all the columns padding padding is also given as 10 and five and we have finally root.
main Loop this line starts the event Loop of the T the application which listens for the user event such as button clicks and updates the GUI accordingly it keeps the GUI window open until the user closes it so quickly let's see the output of the program so as usual I'm going to go where the program is stored copy the name of the program Open command pro at the same window and CMD so you have python space Cod name.