Posts

Creating GUI Applications using tkinter

Download the package tk conda install tk pip install tk # create a new frame from tkinter import * root = Tk() root.geometry("600x250") root.mainloop() # Using Label in Frame from tkinter import * root= Tk() root.geometry("600x250") my_text= Label(root, text= "This is a New Line Text", font=('Helvetica bold', 16)) my_text.pack(pady=30) root.mainloop() # Adding Buttons from tkinter import * from tkinter import ttk win= Tk() win.geometry("400x300") def save():    print("Saved") cmdsave= ttk.Button(win, text="Save",command=lambda:save()) cmdsave.pack() win.mainloop() # Using Images from tkinter import * root= Tk() root.geometry("750x280") canvas= Canvas(root, width=300, height=300) logo = PhotoImage(file='logo.png') canvas.create_image((200, 140), image=logo) canvas.pack() root.mainloop() # Sample GUI Application from tkinter import * fields = ('Annual Rate', 'Number of Payments', 'Lo...

Calling Python Functions from Java

Java Program import org.python.core.PyInstance;   import org.python.util.PythonInterpreter;   class PythonJava  {      PythonInterpreter interpreter = null;      public PythonJava()      {         PythonInterpreter.initialize(System.getProperties(),System.getProperties(), new String[0]);         this.interpreter = new PythonInterpreter();      }      void execfile( final String fileName )      {         this.interpreter.execfile(fileName);      }      PyInstance createClass( final String className, final String opts )      {         return (PyInstance) this.interpreter.eval(className + "(" + opts + ")");      }      public static void main( String ...

Word and Excel Automation using Python

https://www.pylenin.com/blogs/line-charts-openpyxl/ https://towardsdatascience.com/automate-microsoft-excel-and-word-using-python-ab92713b4ffe

Base64 Encryption and Decryption using Python

 # Encrypting a dictionary data into Base64 String import json,base64  record = {"name":"Dr B P Sharma","email":"bpsharma@gmail.com","mobile":"9625372486"} data=json.dumps(record) asciidata = data.encode("ascii")  encodeddata = base64.b64encode(asciidata)  base64_string = encodeddata.decode("ascii")  print(f"Encoded string: {base64_string}")  Output Encoded string: eyJuYW1lIjogIkRyIEIgUCBTaGFybWEiLCAiZW1haWwiOiAiYnBzaGFybWFAZ21haWwuY29tIiwgIm1vYmlsZSI6ICI5NjI1MzcyNDg2In0= # Decrypting a Base64 into String and Dictionary import json,base64    base64_string ="eyJuYW1lIjogIkRyIEIgUCBTaGFybWEiLCAiZW1haWwiOiAiYnBzaGFybWFAZ21haWwuY29tIiwgIm1vYmlsZSI6ICI5NjI1MzcyNDg2In0=" base64_bytes = base64_string.encode("ascii")  decodeddata = base64.b64decode(base64_bytes)  data_string = decodeddata.decode("ascii")  print(f"Decoded string: {sample_string}")  record=json.loads(...

Python Code in Execution Visualization Tool

http://pythontutor.com/visualize.html#mode=display

Using MongoDB with Python

Working with MongoDb A No-SQL database which works to manage data without need of SQL statements We need to install the MongoDb Software as a Service sudo apt-get update sudo apt-get install -y mongodb Starting the MongoDB Service sudo service mongodb start Default is 27017 Stopping the MongoDb Service sudo service mongodb stop Install the package pymongo in conda conda install pymongo  #Adding new record import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["demodb"] mycol = mydb["customer"] cid=input("Enter customer id : ") name=input("Enter Name : ") email=input("Enter email : ") c={ "cid": cid, "name": name, "email":email } mycol.insert_one(c) print("Record added") # View all records import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["demodb...