Skip to content

Instantly share code, notes, and snippets.

@GravenilvecTV
Created February 18, 2019 20:12
Show Gist options
  • Save GravenilvecTV/2240add5bfb3d3fa53f9f98057cad63c to your computer and use it in GitHub Desktop.
Save GravenilvecTV/2240add5bfb3d3fa53f9f98057cad63c to your computer and use it in GitHub Desktop.
from tkinter import *
import webbrowser
class MyApp:
def __init__(self):
self.window = Tk()
self.window.title("My Application")
self.window.geometry("720x480")
self.window.minsize(480, 360)
self.window.iconbitmap("logo.ico")
self.window.config(background='#41B77F')
# initialization des composants
self.frame = Frame(self.window, bg='#41B77F')
# creation des composants
self.create_widgets()
# empaquetage
self.frame.pack(expand=YES)
def create_widgets(self):
self.create_title()
self.create_subtitle()
self.create_youtube_button()
def create_title(self):
label_title = Label(self.frame, text="Bienvenue sur l'application", font=("Courrier", 40), bg='#41B77F',
fg='white')
label_title.pack()
def create_subtitle(self):
label_subtitle = Label(self.frame, text="Hey salut à tous c'est Graven", font=("Courrier", 25), bg='#41B77F',
fg='white')
label_subtitle.pack()
def create_youtube_button(self):
yt_button = Button(self.frame, text="Ouvrir Youtube", font=("Courrier", 25), bg='white', fg='#41B77F',
command=self.open_graven_channel)
yt_button.pack(pady=25, fill=X)
def open_graven_channel(self):
webbrowser.open_new("http://youtube.com/gravenilvectuto")
# afficher
app = MyApp()
app.window.mainloop()
@patrickjuniorsambantadi

merci bcp

@VinyPrestyNakavoua
Copy link

Merci beaucoup Graven

@antoinenowakowski
Copy link

thanks u a lot

@EudinoDev
Copy link

Merci Graven

@AbeileMiel
Copy link

comment on peut faire pour comme dans ta video avec une barre de menu au dessus avec des fonctions. J'ai essayé , sans réussite.

@elharrak58
Copy link

salut tous le monde j'ai un probleme avec la faction iconbitmap j'arrive pas a importer l'icone il me donne cette erreur
/usr/bin/python3.10 /home/el/PycharmProjects/TEST/ville.py
Traceback (most recent call last):
File "/home/el/PycharmProjects/TEST/ville.py", line 49, in
app = MyApp()
File "/home/el/PycharmProjects/TEST/ville.py", line 12, in init
self.window.iconbitmap("logo.ico")
File "/usr/lib/python3.10/tkinter/init.py", line 2109, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "logo.ico" not defined
pourtant j'ai mis l'icone dans le meme dossier

@QMess500
Copy link

QMess500 commented Jan 9, 2023

Hello @elharrak58,
J'ai déjà eu cette erreur, je l'ai simplement corrigé en mettant le ''path = chemin" complet de l'objet "l'icone"

Exemple :
self.window.iconbitmap('c:/files/myfiles/icon.ico')

Au lieu de :
self.window.iconbitmap('icon.ico')

Assure toi aussi d'avoir bien convertie ton image en ICO

@christian66-gif
Copy link

christian66-gif commented Apr 23, 2023

bonjour Graven ... tu es doué pour enseigner " partager " ton expérience ... un tout grand merci pour ce gigantesque travail en arrière plan ...
le programme " générateur de mot de passe " est génial .. une référence Bravo, Bravo ....

image

image réalisée avec Paint3D sous Windows 10

@christian66-gif
Copy link

christian66-gif commented Apr 24, 2023

bonjour Graven ... j'ai tenté de faire le TP avec les cookies ... me suis un peu mélangé les pinceaux avec les compteurs mais le résultat est cool :)
ps: le lien vers la page de la correction ne fonctionne pas ... je dépose un petit print screen ici ... le code je le déposerai sur l'autre lien.

image

images réalisées avec Bing AI Creator sous Edge... Gif animé avec Gimp

@XxMHDxX
Copy link

XxMHDxX commented Mar 28, 2024

est ce que quelqu'un me dit pourquoi ca marche pas chez moi
import tkinter as tk
from tkinter import *

#creer la fenetre
window = tk.Tk()
window.title("Generateur de mot de passe")
window.geometry("720x480")
window.config(background='#ECEFF1')

#creer la frame principale
frame = Frame(window, bg='#ECEFF1')

#creation d'image
width = 400
height = 400
image = PhotoImage(file="password-manager.png").zoom(35).subsample(32)
image = image.subsample(2)
canvas = Canvas(window, width=width, height=height, bg='#ECEFF1', bd=0, highlightthickness=0)
canvas.create_image(width/2, height/2, image=image)
canvas.grid(row=0, column=0, sticky=W)

#creer un titre
label_title = Label(frame, text="Mot de passse", font=("Helvetica",20), bg='#ECEFF1', fg='black')
label_title.grid(row=0, column=1, sticky=W)

#afficher la frame
frame.pack(expand=tk.YES)

#afficher la fenetre
window.mainloop()
ca me dit ya un probleme avec pack et grid

@iamabdoulaziz
Copy link

je sais pas si t'as déjà pu trouver la solution mais je crois que dans la partie afficher le frame tu devrais ecrire frame.pack(expand= YES) , sans le tk là

@iamabdoulaziz
Copy link

Et merci Graven , ça fait un bout de temps que j'essaie d'apprendre Python mais je procrastinais tout le temps mais maintenant je suis à fond dessus et grâce à tes vidéos j'apprends plus plus que tout ce que j'ai fait en 3 ans de licence en développement de logiciel dans mon université so un grand merci
Thank you a lot .

@Proxdlahess
Copy link

Je sais que c'est pas le bon endroit mais vu que la correction du Tp a été supprimer je vais mettre ma correction ici :
(C'est que le point 1 et 2), aussi si vous voulez mettre un code python en couleur il faut écrire sa tout au dessus du code : ```python

from tkinter import *

def Cokkie_app():
    window = Tk()
    # Initialiser le compteur
    click_count = 0

    def windows():
        window.title("Cokkies party")
        window.geometry("1080x1080")
        window.iconbitmap("")
        window.config(background="#4065A4")

    def crrer_la_frame_proncipal():
        global frame
        frame = Frame(window, bg="#4065A4")
        frame.pack(expand=YES)

    def Créer_un_titre():
        global label_title
        label_title = Label(window, text=f"Vous avez appuyé {click_count} fois", font=("Helvetica", 20), bg="#4065A4", fg="white")
        label_title.pack()

    def increment_click_count():
        global click_count
        click_count += 1
        label_title.config(text=f"Vous avez appuyé {click_count} fois")

    def création_de_image():
        global image  
        largeur = 300
        hauteur = 300
        image = PhotoImage(file="biscuits.png")
        image = image.zoom(30).subsample(50)  
        canvas = Canvas(frame, width=largeur, height=hauteur, bg="#4065A4", bd=0, highlightthickness=0)
        canvas.create_image(largeur/2, hauteur/2, image=image)
        canvas.pack()

    def Créer_un_bouton():
        generate_password_button = Button(frame, text="Appuyer", font=("Helvetica", 20), bg="#4065A4", fg="white", command=increment_click_count)
        generate_password_button.pack(fill=X, pady=10)  

    windows()
    crrer_la_frame_proncipal()
    Créer_un_titre()
    création_de_image()
    Créer_un_bouton()

    return window

app = Cokkie_app()
app.mainloop()

@Proxdlahess
Copy link

est ce que quelqu'un me dit pourquoi ca marche pas chez moi import tkinter as tk from tkinter import *

#creer la fenetre window = tk.Tk() window.title("Generateur de mot de passe") window.geometry("720x480") window.config(background='#ECEFF1')

#creer la frame principale frame = Frame(window, bg='#ECEFF1')

#creation d'image width = 400 height = 400 image = PhotoImage(file="password-manager.png").zoom(35).subsample(32) image = image.subsample(2) canvas = Canvas(window, width=width, height=height, bg='#ECEFF1', bd=0, highlightthickness=0) canvas.create_image(width/2, height/2, image=image) canvas.grid(row=0, column=0, sticky=W)

#creer un titre label_title = Label(frame, text="Mot de passse", font=("Helvetica",20), bg='#ECEFF1', fg='black') label_title.grid(row=0, column=1, sticky=W)

#afficher la frame frame.pack(expand=tk.YES)

#afficher la fenetre window.mainloop() ca me dit ya un probleme avec pack et grid

Teste ce programme :

import tkinter as tk
from tkinter import Frame, PhotoImage, Canvas, Label

# Créer la fenêtre
window = tk.Tk()
window.title("Generateur de mot de passe")
window.geometry("720x480")
window.config(background='#ECEFF1')

# Créer la frame principale
frame = Frame(window, bg='#ECEFF1')

# Création d'image
width = 400
height = 400
image = PhotoImage(file="password-manager.png").zoom(35).subsample(32)
canvas = Canvas(window, width=width, height=height, bg='#ECEFF1', bd=0, highlightthickness=0)
canvas.create_image(width/2, height/2, image=image)
canvas.grid(row=0, column=0, sticky='W')

# Créer un titre
label_title = Label(frame, text="Mot de passse", font=("Helvetica", 20), bg='#ECEFF1', fg='black')
label_title.grid(row=0, column=1, sticky='W')

# Afficher la frame
frame.pack(expand=tk.YES)

# Afficher la fenêtre
window.mainloop()

La sa devrais marcher d'habitude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment