1 2 3 4 5 6 7 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
"""
Teillet Corentin
"""
##########################Importation###########################################
from tkinter import *
import tkinter as tk
from path import Path
import os
import random
###########################Fonction_Utile#######################################
def parcours(nom_dossier, ens_ext, compteur=None):
file_count = 0
dir_count = 0
total = 0
d = Path(nom_dossier)
#Replace DIRECTORY with your required directory
for i in d.walk():
print(i)
if i.isfile():
if i.ext in ens_ext:
file_count += 1
if file_count == compteur:
return i
else:
pass
total += 1
return file_count
def choix_nombre(nom_dossier, ens_ext):
total=parcours(nom_dossier, ens_ext)
print(total)
return random.randint(0, total)
def choix_fichier(nom_dossier, ens_ext):
alea=choix_nombre(nom_dossier, ens_ext)
print(alea)
return parcours(nom_dossier, alea, ens_ext)
def ouvrir(nom_dossier, mp4, mkv, avi, pdf, exe, mp3, flac, JPG):
ens_ext=set()
if mp4:
ens_ext.add('.mp4')
if mkv:
ens_ext.add('.mkv')
if avi:
ens_ext.add('.avi')
if pdf:
ens_ext.add('.pdf')
if exe:
ens_ext.add('.exe')
if mp3:
ens_ext.add('.mp3')
if flac:
ens_ext.add('flac')
if JPG:
ens_ext.add('.JPG')
fichier = choix_fichier(nom_dossier, ens_ext)
#print(fichier)
os.system(fichier)
return fichier
###########################Fonction_Graphique###################################
def saisie():
return entree.get()
#############################Creation_fenetre###################################
root = Tk()
root.geometry("315x330")
###################Menu_en_haut#################################################
menu = Menu(root)
mfile = Menu(menu)
mfile.add_command(label='Fermer', command = root.destroy)
menu.add_cascade(label='File', menu=mfile)
root.configure(menu=menu)
#########################FRAME##################################################
Frame1 = Frame(root, borderwidth=2, relief=GROOVE)
Frame1.pack()
Frame1.place(height=50, width=250, x=30, y=110)
Frame3 = Frame(root, borderwidth=2, relief=GROOVE)
Frame3.pack()
Frame3.place(height=50, width=250, x=30, y=30)
Frame4 = Frame(root, borderwidth=2, relief=GROOVE)
Frame4.pack()
Frame4.place(height=115, width=250, x=30, y=190)
#################Entree#########################################################
value = StringVar()
value.set("Nom de Dossier")
entree = Entry(Frame3, textvariable=value, width=30)
entree.pack(side=LEFT, padx=5)
#########################Bouton#################################################
bvalide = Button(Frame3, text="Valider", command=saisie())
bvalide.pack(side=LEFT, padx=5)
bchance = Button(Frame1, text='Chance', command=lambda :ouvrir(saisie(), mp4, mkv, avi, pdf, exe, mp3, flac, JPG))
bchance.pack(side=LEFT, padx=5)
#########################Variable###############################################
mp4=IntVar()
mkv=IntVar()
avi=IntVar()
pdf=IntVar()
exe=IntVar()
mp3=IntVar()
flac=IntVar()
JPG=IntVar()
#########################Check-boutton##########################################
bmp4 = Checkbutton(Frame4, text=".mp4",variable = mp4)
bmp4.pack()
bmp4.place(x=20, y=5)
bmkv = Checkbutton(Frame4, text=".mkv", variable = mkv)
bmkv.pack()
bmkv.place(x=135, y=5)
bavi = Checkbutton(Frame4, text=".avi", variable = avi)
bavi.pack()
bavi.place(x=20, y=30)
bpdf = Checkbutton(Frame4, text=".pdf", variable = pdf)
bpdf.pack()
bpdf.place(x=135, y=30)
bexe = Checkbutton(Frame4, text=".exe", variable = exe)
bexe.pack()
bexe.place(x=20, y=55)
bmp3 = Checkbutton(Frame4, text=".mp3", variable = mp3)
bmp3.pack()
bmp3.place(x=135, y=55)
bflac = Checkbutton(Frame4, text=".flac", variable = flac)
bflac.pack()
bflac.place(x=20, y=80)
bJPG = Checkbutton(Frame4, text=".JPG", variable = JPG)
bJPG.pack()
bJPG.place(x=135, y=80)
#####################Boucle_fenetre#############################################
root.mainloop()
################################################################################ |