Setup: ====== pip install Pyperclip conda install -c conda-forge Pyperclip ============================================================== ** Random Password Generator ** ================================ # Python program to generate random # password using Tkinter module import random import pyperclip from tkinter import * from tkinter.ttk import * # Function for calculation of password def low(): entry.delete(0, END) # Get the length of password length = var1.get() lower = "abcdefghijklmnopqrstuvwxyz" upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !@#$%^&*()" password = "" # if strength selected is low if var.get() == 1: for i in range(0, length): password = password + random.choice(lower) return password # if strength selected is medium elif var.get() == 0: for i in range(0, length): password = password + random.choice(upper) return password # if strength selected is strong elif var.get() == 3: for i in range(0, length): password = password + random.choice(digits) return password else: print("Please choose an option") # Function for generation of password def generate(): password1 = low() entry.insert(10, password1) # Function for copying password to clipboard def copy1(): random_password = entry.get() pyperclip.copy(random_password) # Main Function # create GUI window root = Tk() var = IntVar() var1 = IntVar() # Title of your GUI window root.title("Random Password Generator") # create label and entry to show # password generated Random_password = Label(root, text="Password") Random_password.grid(row=0) entry = Entry(root) entry.grid(row=0, column=1) # create label for length of password c_label = Label(root, text="Length") c_label.grid(row=1) # create Buttons Copy which will copy # password to clipboard and Generate # which will generate the password copy_button = Button(root, text="Copy", command=copy1) copy_button.grid(row=0, column=2) generate_button = Button(root, text="Generate", command=generate) generate_button.grid(row=0, column=3) # Radio Buttons for deciding the # strength of password # Default strength is Medium radio_low = Radiobutton(root, text="Low", variable=var, value=1) radio_low.grid(row=1, column=2, sticky='E') radio_middle = Radiobutton(root, text="Medium", variable=var, value=0) radio_middle.grid(row=1, column=3, sticky='E') radio_strong = Radiobutton(root, text="Strong", variable=var, value=3) radio_strong.grid(row=1, column=4, sticky='E') combo = Combobox(root, textvariable=var1) # Combo Box for length of your password combo['values'] = (8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, "Length") combo.current(0) combo.bind('<>') combo.grid(column=1, row=1) # start the GUI root.mainloop() ======================================================== ** Simple Calculator ** ======================== # importing Tkinter and math from tkinter import * import math # calc class class calc: def getandreplace(self): """replace x with * and ÷ with /""" self.expression = self.e.get() self.newtext=self.expression.replace('/','/') self.newtext=self.newtext.replace('x','*') def equals(self): """when the equal button is pressed""" self.getandreplace() try: # evaluate the expression using the eval function self.value= eval(self.newtext) except SyntaxError or NameError: self.e.delete(0,END) self.e.insert(0,'Invalid Input!') else: self.e.delete(0,END) self.e.insert(0,self.value) def squareroot(self): """squareroot method""" self.getandreplace() try: # evaluate the expression using the eval function self.value= eval(self.newtext) except SyntaxError or NameError: self.e.delete(0,END) self.e.insert(0,'Invalid Input!') else: self.sqrtval=math.sqrt(self.value) self.e.delete(0,END) self.e.insert(0,self.sqrtval) def square(self): """square method""" self.getandreplace() try: #evaluate the expression using the eval function self.value= eval(self.newtext) except SyntaxError or NameError: self.e.delete(0,END) self.e.insert(0,'Invalid Input!') else: self.sqval=math.pow(self.value,2) self.e.delete(0,END) self.e.insert(0,self.sqval) def clearall(self): """when clear button is pressed,clears the text input area""" self.e.delete(0,END) def clear1(self): self.txt=self.e.get()[:-1] self.e.delete(0,END) self.e.insert(0,self.txt) def action(self,argi): """pressed button's value is inserted into the end of the text area""" self.e.insert(END,argi) def __init__(self,master): """Constructor method""" master.title('Calculator') master.geometry() self.e = Entry(master) self.e.grid(row=0,column=0,columnspan=6,pady=3) self.e.focus_set() #Sets focus on the input text area # Generating Buttons Button(master,text="=",width=11,height=3,fg="blue", bg="orange",command=lambda:self.equals()).grid( row=4, column=4,columnspan=2) Button(master,text='AC',width=5,height=3, fg="red", bg="light green", command=lambda:self.clearall()).grid(row=1, column=4) Button(master,text='C',width=5,height=3, fg="red",bg="light green", command=lambda:self.clear1()).grid(row=1, column=5) Button(master,text="+",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action('+')).grid(row=4, column=3) Button(master,text="x",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action('x')).grid(row=2, column=3) Button(master,text="-",width=5,height=3, fg="red",bg="light green", command=lambda:self.action('-')).grid(row=3, column=3) Button(master,text="÷",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action('/')).grid(row=1, column=3) Button(master,text="%",width=5,height=3, fg="red",bg="light green", command=lambda:self.action('%')).grid(row=4, column=2) Button(master,text="7",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action('7')).grid(row=1, column=0) Button(master,text="8",width=5,height=3, fg="red",bg="light green", command=lambda:self.action(8)).grid(row=1, column=1) Button(master,text="9",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action(9)).grid(row=1, column=2) Button(master,text="4",width=5,height=3, fg="red",bg="light green", command=lambda:self.action(4)).grid(row=2, column=0) Button(master,text="5",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action(5)).grid(row=2, column=1) Button(master,text="6",width=5,height=3, fg="white",bg="blue", command=lambda:self.action(6)).grid(row=2, column=2) Button(master,text="1",width=5,height=3, fg="red",bg="light green", command=lambda:self.action(1)).grid(row=3, column=0) Button(master,text="2",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action(2)).grid(row=3, column=1) Button(master,text="3",width=5,height=3, fg="white",bg="blue", command=lambda:self.action(3)).grid(row=3, column=2) Button(master,text="0",width=5,height=3, fg="white",bg="blue", command=lambda:self.action(0)).grid(row=4, column=0) Button(master,text=".",width=5,height=3, fg="red",bg="light green", command=lambda:self.action('.')).grid(row=4, column=1) Button(master,text="(",width=5,height=3, fg="white",bg="blue", command=lambda:self.action('(')).grid(row=2, column=4) Button(master,text=")",width=5,height=3, fg="blue",bg="orange", command=lambda:self.action(')')).grid(row=2, column=5) Button(master,text="?",width=5,height=3, fg="red",bg="light green", command=lambda:self.squareroot()).grid(row=3, column=4) Button(master,text="x²",width=5,height=3, fg="white",bg="blue", command=lambda:self.square()).grid(row=3, column=5) # Driver Code root = Tk() obj=calc(root) # object instantiated root.mainloop()