Probleme de loop tkinter [Résolu]

Signaler
-
Messages postés
431
Date d'inscription
lundi 23 mars 2020
Statut
Membre
Dernière intervention
22 octobre 2020
-
Bonjour/Bonsoir a tous, mon programme consiste a aidé les utilisateur a répartir leur images et leur gifs dans 2 dossier (pour le moment) en affichant cette image ou ce gif a l'écran et affiche les détail de limage(nom du fichier et "détail visuel") mais quand un gif est affiché, on ne peut pas revenir a un autre type de fichier ou parfois on ne peut carrément pas passé d'un gif a un autre (les deux font une sorte de fusion bizarre).
bref un-peut d'aide serait la bien venue pour résoudre ce problème gainant.

voici le code:

import cv2
import glob
import os
import shutil
import tkinter as tK
from tkinter import *
from PIL import Image, ImageTk, GifImagePlugin
from sightengine.client import SightengineClient
pixels_x = 0
pixels_y = 0
infile = "cc"
x = 0
scm = 0
ds = 1
f1t = "x"
f2t = "x"
file = []
img = "x"
GlobalState = False
for infile in glob.glob('*.jpeg'):
file.append(infile)
for infile in glob.glob('*.jpg'):
file.append(infile)
for infile in glob.glob('*.tiff'):
file.append(infile)
for infile in glob.glob('*.gif'):
file.append(infile)
for infile in glob.glob('*.bmp'):
file.append(infile)
for infile in glob.glob('*.png'):
file.append(infile)
for infile in glob.glob('*.webp'):
file.append(infile)
for infile in glob.glob('*.svg'):
file.append(infile)
for infile in glob.glob('*.gif'):
file.append(infile)
nip = len(file)
nil = str(nip)
ButtonNext = "x"
ButtonBack = "x"
ButtonDelete = "x"
ButtonMove1 = "x"
ButtonMove2 = "x"
lb1 = "x"
lb2 = "x"
lb3 = "x"
lb4 = "x"

class maine:
def __init__(self, master):
global x

def image():
global infile, gender2, AgeStr, lb5text, color
global pixels_x
global pixels_y
global x
global img
global ds
global f1t
global f2t
global ButtonNext
global ButtonBack
global ButtonDelete
global ButtonMove1
global ButtonMove2
global lb1
global lb2
global lb3
global lb4
global GlobalState
if ds == 0:
img.destroy()
ButtonMove1.destroy()
ButtonMove2.destroy()
ButtonBack.destroy()
ButtonNext.destroy()
ButtonDelete.destroy()
lb1.destroy()
lb3.destroy()
lb4.destroy()
try:
lb2.destroy()
except:
pass
if x == len(file):
x = 0
if x == -len(file):
x = 0
zoom = 0.5
load = Image.open(file[x])
pixels_x, pixels_y = tuple([int(zoom * x) for x in load.size])
if pixels_x < 250:
pixels_x = pixels_x * 5
pixels_y = pixels_y * 5
if pixels_y < 250:
pixels_x = pixels_x * 5
pixels_y = pixels_y * 5
if pixels_x > 1000:
pixels_x = pixels_x // 2
pixels_y = pixels_y // 2
if pixels_y > 1000:
pixels_x = pixels_x // 2
pixels_y = pixels_y // 2
extension = os.path.splitext(file[x])[1][1:]
#---------------------------------------------------------------------------------------------------------- probleme /!/
if extension == 'gif':
gif = file[x]
try:
gifObject = Image.open(file[x])
gifframe = gifObject.n_frames
except:
gifframe = "1"
gframes = [PhotoImage(file=gif, format='gif -index %i' % (i)) for i in range(gifframe)]

def update(ind):
frame = gframes[ind]
ind += 1
if ind == gifframe:
ind = 0
img.configure(image=frame)
root.after(100, update, ind)

img = Label(root)
img.place(anchor="center", x=960, y=540)
root.after(0, update, 0)
else:
render = ImageTk.PhotoImage(load.resize((pixels_x, pixels_y)))
img = Label(image=render)
img.image = render
img.place(anchor="center", x=960, y=540)
#---------------------------------------------------------------------------------------------------------- probleme /!/ inf: unbreak loop curing change
self.master = master
self.master.geometry("1920x1080")
self.frame = tK.Frame(self.master)
mvt = "move to "
f1txt = str(mvt) + f1t
f2txt = str(mvt) + f2t
ButtonBack = tK.Button(root, text="back", font="Times 20", command=backf, bg='#6E6E6E', fg='#FFFFFF')
ButtonBack.place(x=0, y=1080 - 55)
ButtonNext = tK.Button(root, text="next", font="Times 20", command=nextf, bg='#6E6E6E', fg='#FFFFFF')
ButtonNext.place(anchor="ne", x=1920, y=1080 - 55)
ButtonDelete = tK.Button(root, text="delet file", font="Times 20", command=delf, bg='#FF0000', fg='#FFFFFF')
ButtonDelete.place(x=70, y=1080 - 55)
ButtonMove1 = tK.Button(root, text=f1txt, font="Times 20", command=movef1, bg='#6E6E6E', fg='#FFFFFF')
ButtonMove1.place(x=0, y=1080 - 110)
ButtonMove2 = tK.Button(root, text=f2txt, font="Times 20", command=movef2, bg='#6E6E6E', fg='#FFFFFF')
ButtonMove2.place(anchor="ne", x=1920, y=1080 - 110)
lb1 = tK.Label(root, text=file[x], font="Times 20", bg='#6E6E6E', fg='#FFFFFF')
lb1.pack()
NumberOfInList: int = len(file)
strNumberOfInList: str = str(NumberOfInList)
lb3text = str("number of remaining images: ") + strNumberOfInList
lb3 = tK.Label(root, text=lb3text, bg='#6E6E6E')
lb3.place(x=0, y=0)
ActualPosition = str(x)
lb4text = str("actual image in list: ") + ActualPosition
lb4 = tK.Label(root, text=lb4text, bg='#6E6E6E')
lb4.place(x=0, y=25)
if not GlobalState:
lb5text = "image analysation is off"
color = '#FF0000'
if GlobalState:
lb5text = "image analysation is on"
color = '#008000'
lb5 = tK.Label(root, text=lb5text, font="Times 20", bg='#6E6E6E', fg=color)
lb5.place(anchor="ne", x=1920, y=0)

def key_pressed(event):
key = event.keysym
if key == "Left":
backf()
if key == "Right":
nextf()
if key == "twosuperior":
global GlobalState
GlobalState = not GlobalState
image()
if key == "1":
movef1()
if key == "2":
movef2()
if key == "*":
delf()
root.bind("<Key>", key_pressed)
if GlobalState:
try:
#-----------------------------------------------------------------\/-\/---------------------------- from GAD.py
def highlightFace(net, frame, conf_threshold=0.7):
frameOpencvDnn = frame.copy()
frameHeight = frameOpencvDnn.shape[0]
frameWidth = frameOpencvDnn.shape[1]
blob = cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], True, False)

net.setInput(blob)
detections = net.forward()
FaceBoxes = []
for i in range(detections.shape[2]):
confidence = detections[0, 0, i, 2]
if confidence > conf_threshold:
x1 = int(detections[0, 0, i, 3] * frameWidth)
y1 = int(detections[0, 0, i, 4] * frameHeight)
x2 = int(detections[0, 0, i, 5] * frameWidth)
y2 = int(detections[0, 0, i, 6] * frameHeight)
FaceBoxes.append([x1, y1, x2, y2])
cv2.rectangle(frameOpencvDnn, (x1, y1), (x2, y2), (0, 255, 0),
int(round(frameHeight / 150)),
8)
return frameOpencvDnn, FaceBoxes
args = file[x]

faceProto = "opencv_face_detector.pbtxt"
faceModel = "opencv_face_detector_uint8.pb"
ageProto = "age_deploy.prototxt"
ageModel = "age_net.caffemodel"
genderProto = "gender_deploy.prototxt"
genderModel = "gender_net.caffemodel"

MODEL_MEAN_VALUES = (78.4263377603, 87.7689143744, 114.895847746)
ageList = ['(0-2)', '(4-6)', '(8-12)', '(15-20)', '(25-32)', '(38-43)', '(48-53)', '(60-100)']
genderList = ['Male', 'Female']

faceNet = cv2.dnn.readNet(faceModel, faceProto)
ageNet = cv2.dnn.readNet(ageModel, ageProto)
genderNet = cv2.dnn.readNet(genderModel, genderProto)

video = cv2.VideoCapture(args if args else 0)
padding = 20
while cv2.waitKey(1) < 0:
hasFrame, frame = video.read()
if not hasFrame:
cv2.waitKey()
break

resultImg, faceBoxes = highlightFace(faceNet, frame)
if not faceBoxes:
gender2 = "no face"
AgeStr = ""

for faceBox in faceBoxes:
face = frame[max(0, faceBox[1] - padding):
min(faceBox[3] + padding, frame.shape[0] - 1), max(0, faceBox[0] - padding)
:min(faceBox[2] + padding,
frame.shape[1] - 1)]

blob = cv2.dnn.blobFromImage(face, 1.0, (227, 227), MODEL_MEAN_VALUES, swapRB=False)
genderNet.setInput(blob)
genderPreds = genderNet.forward()
gender = genderList[genderPreds[0].argmax()]
gender2 = f'Gender: {gender}'

ageNet.setInput(blob)
agePreds = ageNet.forward()
age = ageList[agePreds[0].argmax()]
AgeStr = f'Age: {age[1:-1]} years'
client = SightengineClient('973705498', 'yKJPYWrB4hvr2mQcPAAF')
output = client.check('nudity').set_file(file[x])
print(output.raw)
#-------------------------------------------------------------------------------------------------- from GAD.py
except:
pass
lb2txt = str(gender2) + "," + AgeStr

else:
lb2txt = "destroy"
lb2 = tK.Label(root, text=lb2txt, font="Times 20", bg='#6E6E6E', fg='#FFFFFF')
lb2.pack()
if not GlobalState:
lb2.destroy()
ds = 0

def backf():
global x
x = x - 1
image()

def nextf():
global x
x = x + 1
image()

def delf():
global x
os.remove(file[x])
file.remove(file[x])
x = x
image()

def movef1():
global x
new = str(f1t) + "/" + (file[x])
shutil.move(file[x], new)
file.remove(file[x])
x = x
image()

def movef2():
global x
new = str(f2t) + "/" + (file[x])
shutil.move(file[x], new)
file.remove(file[x])
x = x
image()

def fpi():
global f1t
global f2t
f1t = f1.get()
f2t = f2.get()
try:
os.mkdir(f1t)
except:
pass
try:
os.mkdir(f2t)
except:
pass
ButtonLoad.destroy()
f1.destroy()
f2.destroy()
lb6.destroy()
image()

global infile
global pixels_x
global pixels_y
self.master = master
self.master.geometry("200x200")
self.frame = tK.Frame(self.master)
lb6text = str("number of image: ") + nil
lb6 = tK.Label(root, text=lb6text, bg='#6E6E6E')
lb6.pack()
ButtonLoad = tK.Button(root, text="load", command=fpi, bg='#6E6E6E', fg='#FFFFFF')
ButtonLoad.pack()
f1 = Entry(root, bg='#6E6E6E', fg='#FFFFFF')
f1.pack()
f2 = Entry(root, bg='#6E6E6E', fg='#FFFFFF')
f2.pack()


root = tK.Tk()
app = maine(root)
root.config(bg='#2E2E2E')
root.attributes("-fullscreen", True)
root.bind("<Tab>", lambda event: root.attributes("-fullscreen",
not root.attributes("-fullscreen")))
root.mainloop()




Configuration: Windows / Chrome 83.0.4103.116

1 réponse

Messages postés
431
Date d'inscription
lundi 23 mars 2020
Statut
Membre
Dernière intervention
22 octobre 2020
60
Bonjour overline,

En Python, l'indentation étant importante, merci de re poster ton code avec les balises adéquates , ici le mode d'emploi :

https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code