Package: pylejandria
PYLEJANDRIAJavier and I were bored of sending us scripts and functions by whatsapp, so we decided to make a compilation of themost useful functions, even create some together. The project is calledPyLejandriathanks to the library of Alexandria, where it is said that a colossal amount of knowledge resided. The project is not at all serious, but we will try to do the best we can with our current level of programming.MODULESGUICompilation of widgets that take as a basis the widgets of tkinter, can add functions to make simple interfaces in a very simple way without losing flexibility or having new widgets.MATHSet of functions and classes that facilitate mathematics in python, we are aware that there are specialized libraries, but the idea of this module is that it is easy and fast access.MODULEA simple module consisting of an init function to easily generate a new python package. It could in the future be part of a complete tool to maintain packages.TOOLSSet of everyday functions, mostly for debugging, consists of variables, functions and classes that make the interaction of the program with the terminal simpler, but without needing a user interface.UPLOADModule with graphical interface for the management of python packages, has tools for easierly upload the package to GitHub and PyPi, allows you to decide whether to upload to a GitHub repository automatically detecting if the package has one, in addition to not uploading to PyPi in case we only want to update the repository.DOWNLOADpip install pylejandriaor copy fromPyPi.HELPScriptIf you need help you can import the package and use the example function, it will open an interface that will show you all the attributes of the module and its description. This are the following examples, in this case we will see the help of the "gui" module# Import the modulefrompylejandriaimportgui# Run the example if we run the script directlyif__name__=='__main__':gui.example()TerminalOpen your favorite terminal and run the following commands# Import the modulefrompylejandriaimportgui# Run the examplegui.example()TK FILESTk filesare cascade files that wrap around the interface system of thetkintermodule. The idea is to have a structure similar tokivyorQMLfiles, it also has a system of styles with a format similar toCSS. The main idea of this format is to create separate interfaces from the functional file, for a better organization and have the possibility of editing the interface from the code since it is a text file. It should be noted that you should know about the tkinter module.This is theminimal configurationfor a simple window.We start with a "Tk", which is the base widget of tkinter, then with an extra level of indentation we state the properties that we want. Here is the syntax.It is important topay attention to the spaces, since at the moment the project is in the initial phases andthere are no considerations towards these cases. This could change in the future.For simple propertiesproperty_name: property_valueTo call functions of the widget we start the name with a ".".function_name: function_valueTk
    .geometry: '500x500'
    .title: 'Simple UI'
    bg: '#181818'To run the tk file we use this simple code, what it does is import the load of the function from the pylejandria.gui module, then we create a window variable that will store the window built from the given file, we also pass the "__file__" as the second parameter, this is necessary in case we have functions for our interface,   otherwise we can skip it. (But it is recommended to use it in any case.)# Import load from pylejandria.gui modulefrompylejandria.guiimportload# Use this if statement, is important to avoid recursive importsif__name__=='__main__':window=load('gui.tk',__file__)window.mainloop()Now let's see a more complex example to implement functions and the id system. Here is the new syntax.To call a function start the function's name with a "$" then the nameFor example: $changeTo reference an id start the id with a "#" then the idFor example: #topleft_frameIf the function needs arguments then we pass them using "()" around the elements and each value with a " | ".(Notice the spacing)For example: $change(#topleft_frame | "#ff0000" | "#800000")References.self: refers to the widget itself.self.master: refers to the parent of the widget.self[property]: refers to the given property of the widget itself.Any other valuemust follow python´s syntax.For example: '#ff0000', [self, self.master, self['bg']].tk fileTk
    .title: 'Simple UI'
    bg: '#181818'
    Frame
        bg: '#323232'
        .pack: {}
        Frame
            id: 'topleft_frame'
            bg: '#ff0000'
            width: 200
            height: 200
            .grid: {'row': 0, 'column': 0, 'padx': (50, 0), 'pady': (50, 0)}
        Frame
            id: 'topright_frame'
            bg: '#ffff00'
            width: 200
            height: 200
            .grid: {'row': 0, 'column': 1, 'padx': 50, 'pady': (50, 0)}
        Frame
            id: 'bottomleft_frame'
            bg: '#00ffff'
            width: 200
            height: 200
            .grid: {'row': 1, 'column': 0, 'padx': (50, 0), 'pady': 50}
        Frame
            id: 'bottomright_frame'
            bg: '#00ff00'
            width: 200
            height: 200
            .grid: {'row': 1, 'column': 1, 'padx': 50, 'pady': 50}
    Frame
        bg: 'gray'
        .pack: {}
        Button
            text: 'change top left'
            command: $change(#topleft_frame | '#ff0000' | '#800000')
            .grid: {'row': 0, 'column': 0}
        Button
            text: 'change top right'
            command: $change(#topright_frame | '#ffff00' | '#808000')
            .grid: {'row': 0, 'column': 1}
        Button
            text: 'change bottom left'
            command: $change(#bottomleft_frame | '#00ffff' | '#008080')
            .grid: {'row': 0, 'column': 2}
        Button
            text: 'change bottom right'
            command: $change(#bottomright_frame | '#00ff00' | '#008000')
            .grid: {'row': 0, 'column': 3}.py file# Import load from pylejandria.gui modulefrompylejandria.guiimportload# Define the change function, this will be called by the buttonsdefchange(widget:tk.Widget,color1:str,color2:str)->None:"""Change the color of the background of the widget based on its currentcolor. If the current color is equal to the first color then we choose thesecond one and viceversa."""widget['bg']=color1ifwidget['bg']==color2elsecolor2# Use this if statement, is important to avoid recursive importsif__name__=='__main__':window=load(path,__file__)window.mainloop()CREDITSNameUserArmando ChaparroTheCodingStudentLICENSEPyLejandriaby Armando Chaparro is licensed under aMIT License. See LICENSE.md.Copyright © 2022Armando Chaparro