diff --git a/application.py b/application.py new file mode 100644 index 0000000..359d4ca --- /dev/null +++ b/application.py @@ -0,0 +1,119 @@ +import __main__ +from tkinter import * +from tkinter import ttk + + +#! Function: + +def motion_detection(): + print('Motion Detection activated!') + +def audio_lure(): + print('Audio Lure has been set') + +def silent_ventilation(): + print('Silent Ventilation is active') + window.deiconify() + +def quit(): + print('You have quit!') + window.withdraw() + +def action(): + pass + +def submit(): + + search_result = entry.get() + + if(search_result == "MONETZ"): + print("You did right!") + else: + print("Not that one! Try again.") + +#! Application: + +#? Window +window = Tk() + +window.geometry('420x420') +window.title("V.I.S.E. Application") +icon = PhotoImage(file='Python/Projects/gui/logo.png') +window.iconphoto(True,icon) +#window.config(background="#5cfcff") # HEX color also supportive + + +#? Internal variables +int_x = IntVar() +int_y = IntVar() + + +#? Menubar +menubar = Menu(window) +window.config(menu=menubar) + +#* File Menu +fileMenu = Menu(menubar, tearoff=0, font=("Consolas", 15)) +menubar.add_cascade(label="Menu", menu=fileMenu) +fileMenu.add_command(label="Motion Detection", command=motion_detection, compound='left') +fileMenu.add_command(label="Audio Lure", command=audio_lure, compound='left') +fileMenu.add_command(label="Silent Ventilation", command=silent_ventilation, compound='left') +fileMenu.add_separator() +fileMenu.add_command(label="Exit", command=quit, compound='left' ) + +#* Edit Menu +edit_menu = Menu(menubar, tearoff=0, font=("Consolas", 15)) +menubar.add_cascade(label="Extra", menu=edit_menu) +edit_menu.add_command(label="Camera", compound='left') +edit_menu.add_command(label="Mic", compound='left') +edit_menu.add_command(label="Mute", compound='left') + +#* Social Media Menu +# sm = social media +sm_menu = Menu(menubar, tearoff=0, font=("Consolas", 15)) +menubar.add_cascade(label="Social Media", menu=sm_menu) +sm_menu.add_command(label="Telegram", compound='left') +sm_menu.add_command(label="X", compound='left') +sm_menu.add_command(label="LinkedIn", compound='left') + + +#? Notebook +notebook = ttk.Notebook(window) + +tab1 = Frame(notebook) # new frame for tab 1 +tab2 = Frame(notebook) # new frame for tab 2 +tab3 = Frame(notebook) # new frame for tab 3 + +#? Entry +entry = Entry() +entry.pack() + +submit = Button(window, text="Submit", command=submit) +submit.pack() + + + + + +notebook.add(tab1, text="Motion Detection") +notebook.add(tab2, text="Audio Lure") +notebook.add(tab3, text="Silent Ventilation") +notebook.pack(expand=True, fill="both") + +Label(tab1, text="Welcome to the 'Motion Detection' tool!", width=50, height=25).pack() +Label(tab2, text="Welcome to the 'Audio Lure' tool!", width=50, height=25).pack() +Label(tab3, text="Welcome to the 'Silent Ventilation' tool!", width=50, height=25).pack() + + +#? Button +action = Button(window, text='Action', command=action, font=("Consolas")).pack(side = RIGHT) +do = Button(window, text='Do', command=action, font=("Consolas")).pack(side = LEFT) + + + + + +window.mainloop() + +if __name__ == __main__: + print('this is the script area') \ No newline at end of file diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..7f83898 --- /dev/null +++ b/calculator.py @@ -0,0 +1,127 @@ +from tkinter import * + +def button_press(num): + + global equation_text + + equation_text = equation_text + str(num) + + equation_label.set(equation_text) + +def equals(): + + global equation_text + + try: + total = str(eval(equation_text)) + + equation_label.set(total) + + equation_text = total + + except ZeroDivisionError: + + equation_label.set("arithmetic error") + + equation_text = "" + + except SyntaxError: + + equation_label.set("syntax error") + + equation_text = "" + + +def clear(): + + global equation_text + + equation_label.set("") + + equation_text = "" + +window = Tk() +window.title("VISE's Calculator program") +window.geometry("500x500") + +equation_text = "" + +equation_label = StringVar() + +label = Label(window, textvariable=equation_label, font=('consolas', 20), bg="white", width=24, height=2) +label.pack() + +frame = Frame(window) +frame.pack() + +button1 = Button(frame, text=1, height=4, width=9, font=35, + command= lambda: button_press(1)) +button1.grid(row=0, column=0) + +button2 = Button(frame, text=2, height=4, width=9, font=35, + command= lambda: button_press(2)) +button2.grid(row=0, column=1) + +button3 = Button(frame, text=3, height=4, width=9, font=35, + command= lambda: button_press(3)) +button3.grid(row=0, column=2) + +button4 = Button(frame, text=4, height=4, width=9, font=35, + command= lambda: button_press(4)) +button4.grid(row=1, column=0) + +button5 = Button(frame, text=5, height=4, width=9, font=35, + command= lambda: button_press(5)) +button5.grid(row=1, column=1) + +button6 = Button(frame, text=6, height=4, width=9, font=35, + command= lambda: button_press(6)) +button6.grid(row=1, column=2) + +button7 = Button(frame, text=7, height=4, width=9, font=35, + command= lambda: button_press(7)) +button7.grid(row=2, column=0) + +button8 = Button(frame, text=8, height=4, width=9, font=35, + command= lambda: button_press(8)) +button8.grid(row=2, column=1) + +button9 = Button(frame, text=9, height=4, width=9, font=35, + command= lambda: button_press(9)) +button9.grid(row=2, column=2) + +button0 = Button(frame, text=0, height=4, width=9, font=35, + command= lambda: button_press(0)) +button0.grid(row=3, column=1) + +plus = Button(frame, text='+', height=4, width=9, font=35, + command= lambda: button_press('+')) +plus.grid(row=0, column=3) + +minus = Button(frame, text='-', height=4, width=9, font=35, + command= lambda: button_press('-')) +minus.grid(row=1, column=3) + +multiply = Button(frame, text='*', height=4, width=9, font=35, + command= lambda: button_press('*')) +multiply.grid(row=2, column=3) + +divide = Button(frame, text='/', height=4, width=9, font=35, + command= lambda: button_press('/')) +divide.grid(row=3, column=3) + +equal = Button(frame, text='=', height=4, width=9, font=35, + command=equals) +equal.grid(row=3, column=2) + +decimal = Button(frame, text='.', height=4, width=9, font=35, + command= lambda: button_press('.')) +decimal.grid(row=3, column=0) + +clear = Button(window, text='clear', height=4, width=12, font=35, + command=clear) +clear.pack() + + + +window.mainloop() \ No newline at end of file diff --git a/clock.py b/clock.py new file mode 100644 index 0000000..5a74d21 --- /dev/null +++ b/clock.py @@ -0,0 +1,29 @@ +from tkinter import * +from time import * + +def update(): + time_string = strftime("%I:%M:%S %p") + time_label.config(text=time_string) + + day_string = strftime("%A") + day_label.config(text=day_string) + + date_string = strftime("%B %d, %Y") + date_label.config(text=date_string) + + window.after(1000, update) # delay for 1000 milliseconds + +window = Tk() + +time_label = Label(window, font=("Arial", 50), fg="#00FF00", bg="black") +time_label.pack() + +day_label = Label(window, font=("Ink Free", 25)) +day_label.pack() + +date_label = Label(window, font=("Ink Free", 30)) +date_label.pack() + +update() + +window.mainloop() \ No newline at end of file diff --git a/hide_show.py b/hide_show.py new file mode 100644 index 0000000..5d148e7 --- /dev/null +++ b/hide_show.py @@ -0,0 +1,21 @@ +import tkinter as tk + +def hide_window(): + root.withdraw() # Скрыть окно + +def show_window(): + root.deiconify() # Показать окно + +root = tk.Tk() +root.title("Пример с withdraw()") + +# Кнопка для скрытия окна +hide_button = tk.Button(root, text="Скрыть окно", command=hide_window) +hide_button.pack(pady=20) + +# Кнопка для восстановления окна +show_button = tk.Button(root, text="Показать окно", command=show_window) +show_button.pack(pady=20) + +root.geometry("300x200") +root.mainloop() diff --git a/snaker.py b/snaker.py new file mode 100644 index 0000000..845b1ea --- /dev/null +++ b/snaker.py @@ -0,0 +1,174 @@ +from tkinter import * +import random + + +# Constants +GAME_WIDTH = 700 +GAME_HEIGHT = 700 +SPEED = 100 # 50 is fast +SPACE_SIZE = 25 # 25 is small +BODY_PARTS = 3 +SNAKE_COLOR = "#00FF00" # blue = #0000FF, green = #00FF00 +FOOD_COLOR = "#FF0000" # yellow = #FFFF00, red = #FF0000 +BACKGROUND_COLOR = "#000000" # white = #FFFFFF, black = #000000 + + +class Snake: + + def __init__(self): + self.body_size = BODY_PARTS + self.coordinates = [] + self.squares = [] # list of square graphics + + for i in range(0, BODY_PARTS): + self.coordinates.append([0, 0]) # snake will appear on the top left corner + + for x, y in self.coordinates: + square = canvas.create_rectangle(x, y, x + SPACE_SIZE, y + SPACE_SIZE, fill=SNAKE_COLOR, tag="snake") + self.squares.append(square) + +class Food: # 700 / 50 = 14 possible spots on x and y axis + + def __init__(self): + + x = random.randint(0, int((GAME_WIDTH / SPACE_SIZE)) - 1) * SPACE_SIZE + y = random.randint(0, int((GAME_HEIGHT / SPACE_SIZE)) - 1) * SPACE_SIZE + + self.coordinates = [x, y] + + canvas.create_oval(x, y, x + SPACE_SIZE, y + SPACE_SIZE, fill=FOOD_COLOR, tag="food") + +def next_turn(snake, food): + + x, y = snake.coordinates[0] + + if direction == "up": + y -= SPACE_SIZE + + elif direction == "down": + y += SPACE_SIZE + + elif direction == "left": + x -= SPACE_SIZE + + elif direction == "right": + x += SPACE_SIZE + + else: + pass + + snake.coordinates.insert(0, (x, y)) + + square = canvas.create_rectangle(x, y, x + SPACE_SIZE, y + SPACE_SIZE, fill=SNAKE_COLOR) + + snake.squares.insert(0, square) + + + if x == food.coordinates[0] and y == food.coordinates[1]: + + global score + + score += 1 + + label.config(text="Score:{}".format(score)) + + canvas.delete("food") # deleting the object with tag 'food' line 39 + + food = Food() + + else: + del snake.coordinates[-1] # deletes last part of body + + canvas.delete(snake.squares[-1]) + + del snake.squares[-1] + + if check_collisions(snake): + game_over() + + else: + window.after(SPEED, next_turn, snake, food) + +def change_direction(new_direction): + + global direction + + if new_direction == 'left': + if direction != 'right': + direction = new_direction + + elif new_direction == 'right': + if direction != 'left': + direction = new_direction + + elif new_direction == 'up': + if direction != 'down': + direction = new_direction + + elif new_direction == 'down': + if direction != 'up': + direction = new_direction + +def check_collisions(snake): + + x, y = snake.coordinates[0] + + if x < 0 or x >= GAME_WIDTH: + print("GAME OVER") + return True + + elif y < 0 or y >= GAME_HEIGHT: + print("GAME OVER") + return True + + for body_part in snake.coordinates[1:]: # check everything after the head of the snake + if x == body_part[0] and y == body_part[1]: + print("GAME OVER") + return True + + return False # if there is no any collisions + +def game_over(): + + canvas.delete(ALL) + canvas.create_text(canvas.winfo_width()/2, canvas.winfo_height()/2, + font=('consolas', 70), text="GAME OVER", fill="red", tag="gameover") + +window = Tk() +window.title("Snaker") + +window.resizable(False, False) # double False required I guess for width and height + +score = 0 +direction = 'down' + +label = Label(window, text="Score:{}".format(score), font=('consolas', 40)) +label.pack() + +canvas = Canvas(window, bg=BACKGROUND_COLOR, height=GAME_HEIGHT, width=GAME_WIDTH) +canvas.pack() + +window.update() + +window_width = window.winfo_width() +window_height = window.winfo_height() +screen_width = window.winfo_screenwidth() +screen_height = window.winfo_screenheight() + +x = int((screen_width/2) - (window_width/2)) +y = int((screen_height/2) - (window_height/2)) + +window.geometry(f"{window_width}x{window_height}+{x}+{y}") + +snake = Snake() +food = Food() + +window.bind('', lambda event: change_direction('left')) +window.bind('', lambda event: change_direction('right')) +window.bind('', lambda event: change_direction('up')) +window.bind('', lambda event: change_direction('down')) + +next_turn(snake, food) + + +window.mainloop() \ No newline at end of file diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py new file mode 100644 index 0000000..4e8800a --- /dev/null +++ b/tempCodeRunnerFile.py @@ -0,0 +1 @@ +SIZE, y + SPACE_SIZE, fill=FOOD_COLOR, tag="food") diff --git a/tic_tac_toe.py b/tic_tac_toe.py new file mode 100644 index 0000000..da37dc4 --- /dev/null +++ b/tic_tac_toe.py @@ -0,0 +1,127 @@ +from tkinter import * +import random + +def next_turn(row, column): + + global player + + if buttons[row][column]['text'] == "" and check_winner() is False: # just to access to the text of the button + + if player == players[0]: # we could just write "x", but it will be less flexible because player will shoose its nickname + + buttons[row][column]['text'] = player + + if check_winner() is False: + player = players[1] + label.config(text=(players[1] + " turn")) + + elif check_winner() is True: + label.config(text=(players[0] + " wins")) + + elif check_winner() == "Tie": + label.config(text=("Tie!")) + + else: + + buttons[row][column]['text'] = player + + if check_winner() is False: + player = players[0] + label.config(text=(players[0]+ " turn")) + + elif check_winner() is True: + label.config(text=(players[1]+ " wins")) + + elif check_winner() == "Tie": + label.config(text=("Tie!")) + +def check_winner(): + + for row in range(3): + if buttons[row][0]['text'] == buttons[row][1]['text'] == buttons[row][2]['text'] != "": + buttons[row][0].config(bg="green") + buttons[row][1].config(bg="green") + buttons[row][2].config(bg="green") + return True + + for column in range(3): + if buttons[0][column]['text'] == buttons[1][column]['text'] == buttons[2][column]['text'] != "": + buttons[0][column].config(bg="green") + buttons[1][column].config(bg="green") + buttons[2][column].config(bg="green") + return True + + if buttons[0][0]['text'] == buttons[1][1]['text'] == buttons[2][2]['text'] != "": # right diagonal + buttons[0][0].config(bg="green") + buttons[1][1].config(bg="green") + buttons[2][2].config(bg="green") + return True + + elif buttons[0][2]['text'] == buttons[1][1]['text'] == buttons[2][0]['text'] != "": # left diagonal + buttons[0][2].config(bg="green") + buttons[1][1].config(bg="green") + buttons[2][0].config(bg="green") + return True + + elif empty_spaces() is False: + + for row in range(3): + for column in range(3): + buttons[row][column].config(bg="yellow") + + return "Tie" + + else: + return False + +def empty_spaces(): + + spaces = 9 + + for row in range(3): + for column in range(3): + if buttons[row][column]['text'] != "": + spaces -= 1 + + if spaces == 0: + return False + + else: + return True + +def new_game(): + + global player + + player = random.choice(players) + + label.config(text = player + " turn") + + for row in range(3): + for column in range(3): + buttons[row][column].config(text = "", bg = "#F0F0F0") + +window = Tk() +window.title("Tic Tac TOe") +players = ["$", "@"] # we can embed user's input fucntion +player = random.choice(players) +buttons = [[0,0,0], + [0,0,0], + [0,0,0]] + +label = Label(text = player + " turn", font=('consolas', 40)) +label.pack(side="top") + +reset_button = Button(text="restart", font=('consolas', 20), command=new_game) +reset_button.pack(side="top") + +frame = Frame(window) +frame.pack() + +for row in range(3): + for column in range(3): + buttons[row][column] = Button(frame, text="", font=('consolas', 40), width=5, height=2, + command= lambda row=row, column=column: next_turn(row, column)) + buttons[row][column].grid(row=row, column=column) + +window.mainloop() \ No newline at end of file