├── LICENSE ├── README.md ├── digital clock ├── fidget spinner using gui ├── rock paper scissor ├── simple gui calculator ├── simple hangman game └── weight converter gui /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Supreeth2319 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-programming 2 | This repository have functions related to python modules 3 | -------------------------------------------------------------------------------- /digital clock: -------------------------------------------------------------------------------- 1 | from tkinter import Label, Tk 2 | import time 3 | app_window = Tk() 4 | app_window.title("Digital Clock") 5 | app_window.geometry("430x180") 6 | app_window.resizable(1,1) 7 | 8 | text_font= ("Boulder", 68, 'bold') 9 | background = "#00ffff" 10 | foreground= "#000000" 11 | border_width = 25 12 | 13 | label = Label(app_window, font=text_font, bg=background, fg=foreground, bd=border_width) 14 | label.grid(row=0, column=1) 15 | 16 | def digital_clock(): 17 | time_live = time.strftime("%H:%M:%S") 18 | label.config(text=time_live) 19 | label.after(200, digital_clock) 20 | 21 | digital_clock() 22 | app_window.mainloop() 23 | -------------------------------------------------------------------------------- /fidget spinner using gui: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | state = {'turn': 0} 3 | def spinner(): 4 | clear() 5 | angle = state['turn']/10 6 | right(angle) 7 | forward(100) 8 | dot(80, 'violet') 9 | back(100) 10 | right(51.4285) 11 | forward(100) 12 | dot(80, 'indigo') 13 | back(100) 14 | right(51.4285) 15 | forward(100) 16 | dot(80, 'blue') 17 | back(100) 18 | right(51.4285) 19 | forward(100) 20 | dot(80, 'green') 21 | back(100) 22 | right(51.4285) 23 | forward(100) 24 | dot(80, 'yellow') 25 | back(100) 26 | right(51.4285) 27 | forward(100) 28 | dot(80, 'orange') 29 | back(100) 30 | right(51.4285) 31 | forward(100) 32 | dot(80, 'red') 33 | back(100) 34 | right(51.4285) 35 | update() 36 | def animate(): 37 | if state['turn']>0: 38 | state['turn']-=1 39 | 40 | spinner() 41 | ontimer(animate, 20) 42 | def flick(): 43 | state['turn']+=10 44 | setup(420, 420, 370, 0) 45 | hideturtle() 46 | tracer(False) 47 | width(20) 48 | onkey(flick, 'space') 49 | listen() 50 | animate() 51 | done() 52 | -------------------------------------------------------------------------------- /rock paper scissor: -------------------------------------------------------------------------------- 1 | import random 2 | while True: 3 | print("1--rock,2--paper,3--scissor") 4 | print("--------------------------") 5 | uc=int(input("Enter your choice:")) 6 | print("The User Choicee is ",uc) 7 | if(uc==1): 8 | print("User Choice is ROCK") 9 | elif(uc==2): 10 | print("User Choice is PAPER") 11 | elif(uc==3): 12 | print("User Choice is SCISSOR") 13 | else: 14 | print("Invalid statement,Try again") 15 | continue 16 | cc=random.randint(1,3) 17 | print("Computer Choice is",cc) 18 | if(uc==1 and cc==2): 19 | print("Computer Wins") 20 | elif(uc==1 and cc==3): 21 | print("User Wins") 22 | elif(uc==2 and cc==3): 23 | print("Computer Wins") 24 | elif(uc==2 and cc==1): 25 | print("User Wins") 26 | elif(uc==3 and cc==1): 27 | print("Computer Wins") 28 | elif(uc==3 and cc==2): 29 | print("User Wins") 30 | elif(uc==cc): 31 | print("Match Tie") 32 | ans=input("Do you want to continue?yes or no:") 33 | if(ans=="yes"): 34 | continue 35 | elif(ans=="no"): 36 | print("Thank You") 37 | break 38 | -------------------------------------------------------------------------------- /simple gui calculator: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | win = Tk() # This is to create a basic window 4 | win.geometry("312x324") # this is for the size of the window 5 | win.resizable(0, 0) # this is to prevent from resizing the window 6 | win.title("Calculator") 7 | 8 | ###################Starting with functions #################### 9 | # 'btn_click' function : 10 | # This Function continuously updates the 11 | # input field whenever you enter a number 12 | 13 | def btn_click(item): 14 | global expression 15 | expression = expression + str(item) 16 | input_text.set(expression) 17 | 18 | # 'bt_clear' function :This is used to clear 19 | # the input field 20 | 21 | def bt_clear(): 22 | global expression 23 | expression = "" 24 | input_text.set("") 25 | 26 | # 'bt_equal':This method calculates the expression 27 | # present in input field 28 | 29 | def bt_equal(): 30 | global expression 31 | result = str(eval(expression)) # 'eval':This function is used to evaluates the string expression directly 32 | input_text.set(result) 33 | expression = "" 34 | 35 | expression = "" 36 | 37 | # 'StringVar()' :It is used to get the instance of input field 38 | 39 | input_text = StringVar() 40 | 41 | # Let us creating a frame for the input field 42 | 43 | input_frame = Frame(win, width=312, height=50, bd=0, highlightbackground="black", highlightcolor="black", highlightthickness=2) 44 | 45 | input_frame.pack(side=TOP) 46 | 47 | #Let us create a input field inside the 'Frame' 48 | 49 | input_field = Entry(input_frame, font=('arial', 18, 'bold'), textvariable=input_text, width=50, bg="#eee", bd=0, justify=RIGHT) 50 | 51 | input_field.grid(row=0, column=0) 52 | 53 | input_field.pack(ipady=10) # 'ipady' is internal padding to increase the height of input field 54 | 55 | #Let us creating another 'Frame' for the button below the 'input_frame' 56 | 57 | btns_frame = Frame(win, width=312, height=272.5, bg="grey") 58 | 59 | btns_frame.pack() 60 | 61 | # first row 62 | 63 | clear = Button(btns_frame, text = "C", fg = "black", width = 32, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: bt_clear()).grid(row = 0, column = 0, columnspan = 3, padx = 1, pady = 1) 64 | 65 | divide = Button(btns_frame, text = "/", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("/")).grid(row = 0, column = 3, padx = 1, pady = 1) 66 | 67 | # second row 68 | 69 | seven = Button(btns_frame, text = "7", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(7)).grid(row = 1, column = 0, padx = 1, pady = 1) 70 | 71 | eight = Button(btns_frame, text = "8", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(8)).grid(row = 1, column = 1, padx = 1, pady = 1) 72 | 73 | nine = Button(btns_frame, text = "9", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(9)).grid(row = 1, column = 2, padx = 1, pady = 1) 74 | 75 | multiply = Button(btns_frame, text = "*", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("*")).grid(row = 1, column = 3, padx = 1, pady = 1) 76 | 77 | # third row 78 | 79 | four = Button(btns_frame, text = "4", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(4)).grid(row = 2, column = 0, padx = 1, pady = 1) 80 | 81 | five = Button(btns_frame, text = "5", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(5)).grid(row = 2, column = 1, padx = 1, pady = 1) 82 | 83 | six = Button(btns_frame, text = "6", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(6)).grid(row = 2, column = 2, padx = 1, pady = 1) 84 | 85 | minus = Button(btns_frame, text = "-", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("-")).grid(row = 2, column = 3, padx = 1, pady = 1) 86 | 87 | # fourth row 88 | 89 | one = Button(btns_frame, text = "1", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(1)).grid(row = 3, column = 0, padx = 1, pady = 1) 90 | 91 | two = Button(btns_frame, text = "2", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(2)).grid(row = 3, column = 1, padx = 1, pady = 1) 92 | 93 | three = Button(btns_frame, text = "3", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(3)).grid(row = 3, column = 2, padx = 1, pady = 1) 94 | 95 | plus = Button(btns_frame, text = "+", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("+")).grid(row = 3, column = 3, padx = 1, pady = 1) 96 | 97 | # fourth row 98 | 99 | zero = Button(btns_frame, text = "0", fg = "black", width = 21, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(0)).grid(row = 4, column = 0, columnspan = 2, padx = 1, pady = 1) 100 | 101 | point = Button(btns_frame, text = ".", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click(".")).grid(row = 4, column = 2, padx = 1, pady = 1) 102 | 103 | equals = Button(btns_frame, text = "=", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: bt_equal()).grid(row = 4, column = 3, padx = 1, pady = 1) 104 | 105 | win.mainloop() 106 | -------------------------------------------------------------------------------- /simple hangman game: -------------------------------------------------------------------------------- 1 | import random 2 | print("Welcome to Hangman Game") 3 | print("Guess the word from the topic cricketers") 4 | word=['ishan','hasuranga','siraj','jadeja','duplessis','dhoni','supreeth','harshal','rutherford','virat','ruthuraj'] 5 | word=random.choice(word) 6 | print("Guess the character") 7 | guess="" 8 | guesses=" " 9 | turns=len(word) 10 | while turns>0: 11 | failed=0 12 | for char in word: 13 | if char in guesses: 14 | print(char) 15 | else: 16 | print("__") 17 | failed+=1 18 | if failed==0: 19 | print("You Won the game") 20 | print("The word is ",word) 21 | break 22 | guess=input("guess a character:") 23 | guesses+=guess 24 | if guess not in word: 25 | turns=turns-1 26 | print("Wrong") 27 | print("you have ",turns,"more guesses") 28 | if turns==0: 29 | print("you lost") 30 | -------------------------------------------------------------------------------- /weight converter gui: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | # Creating a GUI Window 3 | window = Tk() 4 | def from_kg(): 5 | gram = float(e2_value.get())*1000 6 | pound = float(e2_value.get())*2.20462 7 | ounce = float(e2_value.get())*35.274 8 | t1.delete("1.0",END) 9 | t1.insert(END, gram) 10 | t2.delete("1.0", END) 11 | t2.insert(END, pound) 12 | t3.delete("1.0", END) 13 | t3.insert(END, ounce) 14 | 15 | e1 = Label(window, text="Input the weight in KG") 16 | e2_value = StringVar() 17 | e2 = Entry(window, textvariable=e2_value) 18 | e3 = Label(window, text="Gram") 19 | e4 = Label(window, text="Pound") 20 | e5 = Label(window, text="Ounce") 21 | 22 | t1 = Text(window, height=5, width=30) 23 | t2 = Text(window, height=5, width=30) 24 | t3 = Text(window, height=5, width=30) 25 | 26 | b1 = Button(window, text="Convert", command=from_kg) 27 | 28 | e1.grid(row=0, column=0) 29 | e2.grid(row=0, column=1) 30 | e3.grid(row=1, column=0) 31 | e4.grid(row=1, column=1) 32 | e5.grid(row=1, column=2) 33 | t1.grid(row=2, column=0) 34 | t2.grid(row=2, column=1) 35 | t3.grid(row=2, column=2) 36 | b1.grid(row=0, column=2) 37 | 38 | window.mainloop() 39 | --------------------------------------------------------------------------------