File Explorer

from tkinter import *

from tkinter import filedialog

def browseFiles():

    filename = filedialog.askopenfilename(initialdir = "/",

                                        title = "Select a File",

                                        filetypes = (("Text files",

                                                        "*.txt*"),

                                                    ("all files",

                                                        "*.*")))

    label_file_explorer.configure(text="File Opened: "+filename)                                                                                              

window = Tk()

window.title('File Explorer')

window.geometry("500x500")

window.config(background = "white")

label_file_explorer = Label(window,

                            text = "File Explorer using Tkinter",

                            width = 100, height = 4,

                            fg = "blue")

button_explore = Button(window,

                        text = "Browse Files",

                        command = browseFiles)

button_exit = Button(window,

                    text = "Exit",

                    command = exit)

label_file_explorer.grid(column = 1, row = 1)

button_explore.grid(column = 1, row = 2)

button_exit.grid(column = 1,row = 3)

window.mainloop()


Screenshot using pyscreenshot

The simplest way of taking a screenshot using pyscreenshot module

Install the package:

               pip install pyscreenshot 


import pyscreenshot

image = pyscreenshot.grab()

image.show()

image.save("screenshot.png")


Flames Checker

def rmv_match_char(list1, list2):

    for i in range(len(list1)):

        for j in range(len(list2)):

            if list1[i] == list2[j]:

                c = list1[i]

                list1.remove(c)

                list2.remove(c)

                list3 = list1 + ["*"] + list2

                return [list3, True]

    list3 = list1 + ["*"] + list2

    return [list3, False]

if __name__ == "__main__":

    p1 = input("Player 1 name : ")

    p1 = p1.lower()

    p1.replace(" ", "")

    p1_list = list(p1)

    p2 = input("Player 2 name : ")

    p2 = p2.lower()

    p2.replace(" ", "")

    p2_list = list(p2)

    proceed = True

    while proceed:

        ret_list = rmv_match_char(p1_list, p2_list)

        con_list = ret_list[0]

        proceed = ret_list[1]

        star_index = con_list.index("*")

        p1_list = con_list[: star_index]

        p2_list = con_list[star_index + 1:]

    count = len(p1_list) + len(p2_list)

    result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"]

    while len(result) > 1:

        split_index = (count % len(result) - 1)

        if split_index >= 0:

            right = result[split_index + 1:]

            left = result[: split_index]

            result = right + left

        else:

            result = result[: len(result) - 1]

    print("Relationship status :", result[0])


Olympic Symbol

import turtle

tr = turtle.Turtle()

tr.pensize(5)

tr.color("blue")

tr.penup()

tr.goto(-110, -25)

tr.pendown()

tr.circle(45)

tr.color("black")

tr.penup()

tr.goto(0, -25)

tr.pendown()

tr.circle(45)

tr.color("red")

tr.penup()

tr.goto(110, -25)

tr.pendown()

tr.circle(45)

tr.color("yellow")

tr.penup()

tr.goto(-55, -75)

tr.pendown()

tr.circle(45)

tr.color("green")

tr.penup()

tr.goto(55, -75)

tr.pendown()

tr.circle(45)


Page Switching

import tkinter as tk

from tkinter import ttk

LARGEFONT =("Verdana", 35)

class switchApp(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)

        container = tk.Frame(self)

        container.pack(side = "top", fill = "both", expand = True)

        container.grid_rowconfigure(0, weight = 1)

        container.grid_columnconfigure(0, weight = 1)

        self.frames = {}

        for F in (StartPage, Page1, Page2):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row = 0, column = 0, sticky ="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):

        frame = self.frames[cont]

        frame.tkraise()

class StartPage(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)

        label = ttk.Label(self, text ="Startpage", font = LARGEFONT)

        label.grid(row = 0, column = 4, padx = 10, pady = 10)

        button1 = ttk.Button(self, text ="Page 1",

        command = lambda : controller.show_frame(Page1))

        button1.grid(row = 1, column = 1, padx = 10, pady = 10)

        button2 = ttk.Button(self, text ="Page 2",

        command = lambda : controller.show_frame(Page2))

        button2.grid(row = 2, column = 1, padx = 10, pady = 10)

class Page1(tk.Frame): 

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)

        label = ttk.Label(self, text ="Page 1", font = LARGEFONT)

        label.grid(row = 0, column = 4, padx = 10, pady = 10)

        button1 = ttk.Button(self, text ="StartPage",

                            command = lambda : controller.show_frame(StartPage))

        button1.grid(row = 1, column = 1, padx = 10, pady = 10)

        button2 = ttk.Button(self, text ="Page 2",

                            command = lambda : controller.show_frame(Page2))

        button2.grid(row = 2, column = 1, padx = 10, pady = 10)

class Page2(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)

        label = ttk.Label(self, text ="Page 2", font = LARGEFONT)

        label.grid(row = 0, column = 4, padx = 10, pady = 10)

        button1 = ttk.Button(self, text ="Page 1",

                            command = lambda : controller.show_frame(Page1))

        button1.grid(row = 1, column = 1, padx = 10, pady = 10)

        button2 = ttk.Button(self, text ="Startpage",

                            command = lambda : controller.show_frame(StartPage))

        button2.grid(row = 2, column = 1, padx = 10, pady = 10)

app = switchApp()

app.mainloop()