Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with pillow
#1
Hello, I made a program with python and I use pillow for open images, the problem is that When I open an image, the program is finished and I can't put loop or anything else, if I do it, it just do the second action and it not opening the image. What could I do ?

for example If I want to print something after the image has open like "congratulation", it will only write the word and won't open the image.

from tkinter import *
from PIL import ImageTk,Image
Images = {1:"2Homo nonhabilis.jpeg",2:"3Pas le feu.jpeg",3:"4ne decouvre pas lart.jpeg",4:"5roue.jpeg",5:"6ecriture.jpeg",6:"pyramide.jpeg",7:"8republic ath.jpeg",8:"9J-C.jpeg",9:"10boussole.jpeg",10: "11christophe colomb.jpeg",11:"12terreplate.jpeg",12:"13 droit de lhomme.jpeg",13:"14 automobile.jpeg",14:"15ww1.jpeg",15:"16ww2.jpeg"}

def un():
    text1 = int(input("Voir la frise normale(1) ou modifier la frise normale(2)"))
    if text1 == 1:
        frisenormal()
    if text1 == 2:
        tout()
    while text1 != 1 or 2:
        print("\n Erreur: Veuillez saisir un chiffre valide. \n")
        un()

def frisenormal():
    main = Tk()
    main.geometry("1260x625+100+100")
    main.title('Frise du monde')
    canvas = Canvas(main,width = 1300,height = 650)
    canvas.place(relx=0,rely=0)
    im = Image.open("1NORMALE.jpeg")
    canvas.image = ImageTk.PhotoImage(im)
    canvas.create_image(0,0,image = canvas.image,anchor='nw')
    
    

def frise(img):
    main = Tk()
    main.geometry("1260x625+100+100")
    main.title('Frise du monde')
    canvas = Canvas(main,width = 1300,height = 650)
    canvas.place(relx=0,rely=0)
    im = Image.open(img)
    canvas.image = ImageTk.PhotoImage(im)
    canvas.create_image(0,0,image = canvas.image,anchor='nw')


def tout():
    with open("ztext.txt", "r") as file_object:
        print(file_object.read())
        tout2()

def tout2():
    texte3 = int(input("choisisez un nombres: "))
    frise(Images[texte3]),
    return


un()
Reply
#2
Everything created in a function is garbage collected when the function exits http://www.tutorialspoint.com/python/pyt...ctions.htm so nothing remains and your program exits. Also there is no mainloop in your program http://python-textbok.readthedocs.io/en/...mming.html
Reply
#3
But why when I try to start a new function at the end of another function who show the image, it only start the new function and don't show the image, I would like to show the image and then start the new function ? is this possible ?



ps: I changed a bit the code

from tkinter import *
from PIL import ImageTk,Image
Images = {1:"2Homo nonhabilis.jpeg",2:"3Pas le feu.jpeg",3:"4ne decouvre pas lart.jpeg",4:"5roue.jpeg",5:"6ecriture.jpeg",6:"pyramide.jpeg",7:"8republic ath.jpeg",8:"9J-C.jpeg",9:"10boussole.jpeg",10: "11christophe colomb.jpeg",11:"12terreplate.jpeg",12:"13 droit de lhomme.jpeg",13:"14 automobile.jpeg",14:"15ww1.jpeg",15:"16ww2.jpeg"}
 
def un():
    text1 = int(input("Voir la frise normale(1) ou modifier la frise normale(2)"))
    if text1 == 1:
        print("Frise affiché")
        main = Tk()
        main.geometry("1260x625+100+100")
        main.title('Frise du monde')
        canvas = Canvas(main,width = 1300,height = 650)
        canvas.place(relx=0,rely=0)
        im = Image.open("1NORMALE.jpeg")
        canvas.image = ImageTk.PhotoImage(im)
        canvas.create_image(0,0,image = canvas.image,anchor='nw')

    if text1 == 2:
        tout()
     
     
     
 
def frise(img):
    main = Tk()
    main.geometry("1260x625+100+100")
    main.title('Frise du monde')
    canvas = Canvas(main,width = 1300,height = 650)
    canvas.place(relx=0,rely=0)
    im = Image.open(img)
    canvas.image = ImageTk.PhotoImage(im)
    canvas.create_image(0,0,image = canvas.image,anchor='nw')
 
 
def tout():
    with open("ztext.txt", "r") as file_object:
        print(file_object.read())
        tout2()
 
def tout2():
    texte3 = int(input("choisisez un nombres: "))
    frise(Images[texte3]),
    return

    
    
 
un()

            
Reply
#4
Posting the same code again serves no purpose. If you did not read what I posted about objects garbage collected, then there is no point in posting. I would suggest that you code this without functions, as you obviously don't understand them, and then move up to a class structure. Switching to a class structure solves a lot of problems (see the second link in my previous post). Post back if you have problems with new code.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020