Python Forum
How to make it shorter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make it shorter
#2
Well, fisrst notice that all your friseX functions are the same except for the file name... you can create just one:
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')
And then store the name of the image that is associated to each index in a dictionary:
images = {1: '2Homo nonhabilis.jpeg', 2: '3Pas le feu.jpeg'} # And so on...
So your chain of if's is replaced by:
frise(images[texte3])
Reply


Messages In This Thread
How to make it shorter - by Lucasesdou - May-06-2018, 04:15 PM
RE: How to make it shorter - by killerrex - May-06-2018, 05:19 PM

Forum Jump:

User Panel Messages

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