Insérer une image avec Tkinter

Résolu/Fermé
willi_4185 Messages postés 41 Date d'inscription jeudi 26 septembre 2019 Statut Membre Dernière intervention 6 octobre 2022 - 29 janv. 2020 à 05:12
willi_4185 Messages postés 41 Date d'inscription jeudi 26 septembre 2019 Statut Membre Dernière intervention 6 octobre 2022 - 31 janv. 2020 à 13:43
Je viens de commencer le Python et j'aimerais savoir comment intégrer une image avec Tkinter
j'ai essayer plusieurs méthode mais aucune n'ont fonctionné

Voici mon code si jamais :

# Coding by Willipro123
import tkinter
from tkinter import Label, Menu, Tk, Checkbutton



# coding:utf-8


# Ici ont viens définir les fonctions principal de notre programme qui nous
# permettront de faire les principaux calcul soit : wallet (Portefeuille) et rps (Donnée entrée par l'utilisateur)

def rps():
    rps = 0

    if __name__ == '__rps__':
        main()


def wallet():
    wallet = 5000

    if __name__ == '__wallet__':
        main()


# Tous les def pour les fonctions
# Options à propos
def propos():
    propos = tkinter.Toplevel(app)
    propos.geometry("240x112")
    propos.title("À propos")
    lb = tkinter.Label(propos, text="""Bienvenue sur mon logiciel de calcul, 
afin que vous puissiez gérer votre argent
Vous pouvez utiliser ce logiciel à des 
fin commerciale, Pour cela il suffit 
de référer la source utiliser 

By William""")
    lb.pack()
    if __name__ == '__propos__':
        main()



def wallet_Menu():
    wallet_Menu = tkinter.Toplevel(app)
    wallet_Menu.geometry("240x140")
    wallet_Menu.title("Wallet_Menu")
    wallet_Menu.resizable(width=False, height=False)
    CH = Checkbutton(wallet_Menu, text="Appuyer ici pour continuer")
    lb = tkinter.Label(wallet_Menu, text="Veuillez entrez vos informations ci-dessous")
    lb2 = tkinter.Label(wallet_Menu, text="Veuillez entrez votre Username : ")
    spr = tkinter.Entry(wallet_Menu, width=24)
    lb3 = tkinter.Label(wallet_Menu, text="Veuillez entrez votre mot de passe : ")
    spr2 = tkinter.Entry(wallet_Menu, width=24, show='*')
    lb.pack()
    lb2.pack()
    spr.pack()
    lb3.pack()
    spr2.pack()
    CH.pack()
    if __name__=='__Wallet_Menu__':
        main()






# retrait
def retrait():
    retrait = tkinter.Toplevel(app)
    retrait.geometry("240x92")
    retrait.title("Retrait")
    lb = tkinter.Label(retrait, text="Entrez le montant que vous souhaitez retirer : ")
    rps = tkinter.Entry(retrait, width=24)
    rps.get()
    lb.pack()
    rps.pack()
    if __name__ == '__retrait__':
        main()


# virement

def virement():
    virement = tkinter.Toplevel(app)
    virement.geometry("240x72")
    virement.title("Virement")
    lb = tkinter.Label(virement, text="Entrez le montant que vous souhaitez virer : ")
    rps = tkinter.Entry(virement, width=24)
    lb.pack()
    rps.pack()
    if __name__ == '__virement__':
        main()


# Ici on vas définir notre fenêtre et les principaux widget :
app = tkinter.Tk()
app.title("Wallet Menu")
mainmenu: Menu = tkinter.Menu(app)
# Ici on vas définir la grandeur de notre fenêtre afin de s'assurer quelle soit bien
# centré par rapport a l'écran

screen_x = int(app.winfo_screenwidth())
screen_y = int(app.winfo_screenheight())
window_x = 480
window_y = 240

posX = (screen_x // 2) - (window_x // 2)
posY = (screen_y // 2) - (window_y // 2)

geo = "{}x{}+{}+{}".format(window_x, window_y, posX, posY)
app.geometry(geo)

#Ici ont viens définir notre background :



# Preminer Menu


first_menu = tkinter.Menu(mainmenu, tearoff=0)
first_menu.add_command(label="Wallet", command=wallet_Menu)
first_menu.add_separator()
first_menu.add_command(label="Virement", command=virement)
first_menu.add_command(label="Retrait", command=retrait)
first_menu.add_separator()
first_menu.add_command(label="Quitter", command=app.quit)

# Second Menu


second_menu = tkinter.Menu(mainmenu, tearoff=0)
second_menu.add_command(label="À propos", command=propos)
second_menu.add_separator()

mainmenu.add_cascade(label="Wallet Option", menu=first_menu)
mainmenu.add_cascade(label="Option", menu=second_menu)

# boucle princiaple

app.config(menu=mainmenu)
app.mainloop()


Merci encore :)

1 réponse

Bonjour,

Où est le code montrant ce que tu as tenté de faire ?
Je ne vois rien dans ce que tu as écrit relatant cela.
0
willi_4185 Messages postés 41 Date d'inscription jeudi 26 septembre 2019 Statut Membre Dernière intervention 6 octobre 2022 3
Modifié le 29 janv. 2020 à 23:36
oui mb ahaha tiens le voici :
# Ici on vas définir notre fenêtre et les principaux widget :
app = tkinter.Tk()
app.title("Wallet Menu")
mainmenu: Menu = tkinter.Menu(app)
# Ici on vas définir la grandeur de notre fenêtre afin de s'assurer quelle soit bien
# centré par rapport a l'écran

screen_x = int(app.winfo_screenwidth())
screen_y = int(app.winfo_screenheight())
window_x = 480
window_y = 240

posX = (screen_x // 2) - (window_x // 2)
posY = (screen_y // 2) - (window_y // 2)

geo = "{}x{}+{}+{}".format(window_x, window_y, posX, posY)
app.geometry(geo)

#Ici ont viens définir notre background 


# Preminer Menu


first_menu = tkinter.Menu(mainmenu, tearoff=0)
first_menu.add_command(label="Wallet", command=wallet_Menu)
first_menu.add_separator()
first_menu.add_command(label="Virement", command=virement)
first_menu.add_command(label="Retrait", command=retrait)
first_menu.add_separator()
first_menu.add_command(label="Quitter", command=app.quit)

# Second Menu


second_menu = tkinter.Menu(mainmenu, tearoff=0)
second_menu.add_command(label="Information de connection", command=Connection_information)
second_menu.add_separator()
second_menu.add_command(label="À propos", command=propos)
second_menu.add_separator()
mainmenu.add_cascade(label="Wallet Option", menu=first_menu)
mainmenu.add_cascade(label="Option", menu=second_menu)



# boucle princiaple

app.config(menu=mainmenu)
app.mainloop()


Sa se passe dans cette zone ci-dessous
j'ai regardé sur le forum de Tkinter pour l'insertion et leur méthode ne fonctionne qu'avec des .gif ce qui n'est pas mon cas, j'ai par la suite chercher sur développez.net mais je n'ai trouver que des insertion d'image pour python sous 2x et non pas 3x comme ce que je cherche
0
trifou > willi_4185 Messages postés 41 Date d'inscription jeudi 26 septembre 2019 Statut Membre Dernière intervention 6 octobre 2022
30 janv. 2020 à 10:42
Bonjour,

Le module tkinter de python3 est à peu près identique que pour python2.
Et je ne vois toujours pas ce que tu as tenté de faire.

Afficher une image avec tkinter c'est tout au plus 10 lignes de code, les formats supportés sont gif et png.

Donc montre ce que tu as tenté de faire.
0