Chaine de caractère en nom de frame tkinter python
Résolu/Fermé
Rolement
-
15 mars 2021 à 17:38
yg_be Messages postés 23526 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 14 avril 2025 - 19 mars 2021 à 19:34
yg_be Messages postés 23526 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 14 avril 2025 - 19 mars 2021 à 19:34
Bonjour,
Je cherche à nommer des frames tkinter comme ça :
note_frame_"le nom de la note" = Frame(paramètre)
Enfaite j'aimerais injecter le nom de ma note dans le nom de la variable qui contient la frame pour contrôler chaque frames indépendamment car si j'en créé plusieurs en les appelants note_frame ça créé des clones incontrôlable.
Est-ce que quelqu'un a une idée ?
Merci d'avance
Je cherche à nommer des frames tkinter comme ça :
note_frame_"le nom de la note" = Frame(paramètre)
Enfaite j'aimerais injecter le nom de ma note dans le nom de la variable qui contient la frame pour contrôler chaque frames indépendamment car si j'en créé plusieurs en les appelants note_frame ça créé des clones incontrôlable.
Est-ce que quelqu'un a une idée ?
Merci d'avance
A voir également:
- Python frame
- Citizen code python avis - Accueil - Outils
- Mot secret python pix ✓ - Forum Python
- Python generator - Télécharger - Sécurité
- Python est introuvable. exúcutez sans argument pour procúder ó l ✓ - Forum Python
7 réponses
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
Ambassadeur
1 577
15 mars 2021 à 17:50
15 mars 2021 à 17:50
bonjour,
as-tu envisagé d'utiliser plutôt un dictionnaire?
as-tu envisagé d'utiliser plutôt un dictionnaire?
Finalement j'ai encore un petit souci.
Avec le code final :
label_old_note = "Nom de la note"
note_frame = {}
note_frame[label_old_note] = Frame(frame2, bg="#FBECBC", width=200, height=60)
note_frame[label_old_note].pack()
J'ai une erreur :
Traceback (most recent call last):
File "/Users/Rolement/PycharmProjects/Note/test.py", line 311, in <module>
old_notes()
File "/Users/Rolement/PycharmProjects/Note/test.py", line 300, in old_notes
label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black",
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 3148, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 2566, in __init__
BaseWidget._setup(self, master, cnf)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 2535, in _setup
self.tk = master.tk
AttributeError: 'dict' object has no attribute 'tk'
Quelqu'un à une idée ?
Merci d'avance
Avec le code final :
label_old_note = "Nom de la note"
note_frame = {}
note_frame[label_old_note] = Frame(frame2, bg="#FBECBC", width=200, height=60)
note_frame[label_old_note].pack()
J'ai une erreur :
Traceback (most recent call last):
File "/Users/Rolement/PycharmProjects/Note/test.py", line 311, in <module>
old_notes()
File "/Users/Rolement/PycharmProjects/Note/test.py", line 300, in old_notes
label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black",
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 3148, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 2566, in __init__
BaseWidget._setup(self, master, cnf)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 2535, in _setup
self.tk = master.tk
AttributeError: 'dict' object has no attribute 'tk'
Quelqu'un à une idée ?
Merci d'avance
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
15 mars 2021 à 21:22
15 mars 2021 à 21:22
prend soin de partager un code que nous puissions tester.
merci, aussi, d'utiliser les balises de code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
merci, aussi, d'utiliser les balises de code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
>
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
15 mars 2021 à 21:30
15 mars 2021 à 21:30
je me demande tout de même ce que tu essaies de faire ici:
label_new_note = Label(note_frame, ...
J'ai pas bien compris ce que tu voulais dire. Tu peux m'expliquer svp ?
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
16 mars 2021 à 16:35
16 mars 2021 à 16:35
1) montre un code assez complet pour que nous puissions le tester.
2) quand tu partages du code, fais comme expliqué: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
2) quand tu partages du code, fais comme expliqué: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question# config note class class Note: def __init__(self, label, subtitle, date_creation, close): self.label = label self.subtitle = subtitle self.date_creation = date_creation self.close = close # config function button def note_click(): label_new_note.config(bg="#FDE098") subtitle_new_note.config(bg="#FDE098") note_frame.config(bg="#FDE098") def button_write(): class PopUp(Tk): def __init__(self): Toplevel.__init__(self) Toplevel.withdraw(self) popup_new_note = Toplevel(self) popup_new_note.title("New Note") popup_new_note.geometry("+225+275") popup_new_note.config(bg="#fffaf6") popup_new_note.tkraise(self) self.mystring = StringVar(popup_new_note) new_note_entry = self.entry = Entry(popup_new_note, textvariable=self.mystring, bd=1, width=35, relief=RIDGE, bg="#fffaf6", highlightthickness=0) new_note_entry.pack(padx=5, pady=3) self.button = Button(popup_new_note, text="OK", command=self.entry_button) self.button.pack(side=BOTTOM) popup_new_note.grab_set() def entry_button(self): new_note_entry_value = self.mystring.get() PopUp.destroy(self) new_note_entry_file = open("note_resource/new_note_title.txt", "w") new_note_entry_file.write(new_note_entry_value) app.quit() app = PopUp() app.mainloop() new_note_entry_value_file = open("note_resource/new_note_title.txt", "r") new_note_entry_value_file_read = new_note_entry_value_file.readline() new_note_label = new_note_entry_value_file_read creation_date_all = datetime.now() creation_date_day = creation_date_all.day if creation_date_day < 10: creation_date_day = str(creation_date_day) creation_date_day = "0" + creation_date_day creation_date_month = creation_date_all.month if creation_date_month < 10: creation_date_month = str(creation_date_month) creation_date_month = "0" + creation_date_month creation_date_year = creation_date_all.year creation_date_year = str(creation_date_year) creation_date = "{}.{}.{}".format(creation_date_day, creation_date_month, creation_date_year) note = Note(new_note_label, "Today", creation_date, False) note_label = note.label note_subtitle = note.subtitle note_date_creation = str(note.date_creation) note_close = note.close new_note_file = open("note_resource/notes/note_{}.txt".format(note_label), "+w") new_note_file.write(note_label + "\n" + note_date_creation + "\n" + "false" + "\n" + "content") note_frame = {} note_frame[note_label] = Frame(frame2, bg="#FBECBC", width=200, height=60) label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black", text=note_label, width=15) subtitle_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 16), fg="#808080", text=note_subtitle, width=15) label_new_note.pack() subtitle_new_note.pack() note_frame[str(note_label)].pack()
Voilà le code plus complet
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
16 mars 2021 à 17:51
16 mars 2021 à 17:51
comment expliqué, peux-tu préciser le langage quand tu utilises les balises?
je n'ai aucun message d'erreur quand j'exécute le code que tu as partagé.
tu n'as pas répondu à ma question du 15 mars 2021 à 21:30
je n'ai aucun message d'erreur quand j'exécute le code que tu as partagé.
tu n'as pas répondu à ma question du 15 mars 2021 à 21:30
Pour le 15 mars à 21:30 je t'ai dit plus haut que je n'avais pas bien compris ce que tu voulais dire. Le problème survient avec la totalité du code python le voici :
Le code n'est pas terminé.
Ce que je faire c'est de créé des frames différente pour chaque notes pour les contrôler indépendament et pouvoir clicker dessus pour les éditer. Le probleme c'est qu'en faisant comme j'ai fait il clone les "note_frame" et je peut donc plus les modifier ou interagir avec elle. Si tu as une solution (dictionnaire ou autre) je serais ravi.
Merci d'avance
# import modules
from tkinter import *
from tkinter.scrolledtext import ScrolledText
from tkmacosx import Button
from tkinter import StringVar
from datetime import *
from os import listdir
from os.path import isfile, join
# recovery of the opening time of the app and stock
opening_time = datetime.now()
year = opening_time.year
month = opening_time.month
day = opening_time.day
hour = opening_time.hour
minute = opening_time.minute
second = opening_time.second
opening_time_file = open("note_resource/opening_time.txt", "w")
opening_time_file.write(str(year))
opening_time_file.write("\n" + str(month))
opening_time_file.write("\n" + str(day))
opening_time_file.write("\n" + str(hour))
opening_time_file.write("\n" + str(minute))
opening_time_file.write("\n" + str(second))
opening_time_file.close()
# config note class
class Note:
def __init__(self, label, subtitle, date_creation, close):
self.label = label
self.subtitle = subtitle
self.date_creation = date_creation
self.close = close
# config function button
def note_click():
label_new_note.config(bg="#FDE098")
subtitle_new_note.config(bg="#FDE098")
note_frame.config(bg="#FDE098")
def button_write():
class PopUp(Tk):
def __init__(self):
Toplevel.__init__(self)
Toplevel.withdraw(self)
popup_new_note = Toplevel(self)
popup_new_note.title("New Note")
popup_new_note.geometry("+225+275")
popup_new_note.config(bg="#fffaf6")
popup_new_note.tkraise(self)
self.mystring = StringVar(popup_new_note)
new_note_entry = self.entry = Entry(popup_new_note, textvariable=self.mystring, bd=1, width=35,
relief=RIDGE, bg="#fffaf6", highlightthickness=0)
new_note_entry.pack(padx=5, pady=3)
self.button = Button(popup_new_note, text="OK", command=self.entry_button)
self.button.pack(side=BOTTOM)
popup_new_note.grab_set()
def entry_button(self):
new_note_entry_value = self.mystring.get()
PopUp.destroy(self)
new_note_entry_file = open("note_resource/new_note_title.txt", "w")
new_note_entry_file.write(new_note_entry_value)
app.quit()
app = PopUp()
app.mainloop()
new_note_entry_value_file = open("note_resource/new_note_title.txt", "r")
new_note_entry_value_file_read = new_note_entry_value_file.readline()
new_note_label = new_note_entry_value_file_read
creation_date_all = datetime.now()
creation_date_day = creation_date_all.day
if creation_date_day < 10:
creation_date_day = str(creation_date_day)
creation_date_day = "0" + creation_date_day
creation_date_month = creation_date_all.month
if creation_date_month < 10:
creation_date_month = str(creation_date_month)
creation_date_month = "0" + creation_date_month
creation_date_year = creation_date_all.year
creation_date_year = str(creation_date_year)
creation_date = "{}.{}.{}".format(creation_date_day, creation_date_month, creation_date_year)
note = Note(new_note_label, "Today", creation_date, False)
note_label = note.label
note_subtitle = note.subtitle
note_date_creation = str(note.date_creation)
note_close = note.close
new_note_file = open("note_resource/notes/note_{}.txt".format(note_label), "+w")
new_note_file.write(note_label + "\n" + note_date_creation + "\n" + "false" + "\n" + "content")
note_frame = {}
note_frame[str(note_label)] = Frame(frame2, bg="#FBECBC", width=200, height=60)
label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black",
text=note_label, width=15)
subtitle_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 16), fg="#808080",
text=note_subtitle, width=15)
label_new_note.pack()
subtitle_new_note.pack()
note_frame[str(note_label)].pack()
def button_delete():
label_new_note.config(bg="#FBECBC")
subtitle_new_note.config(bg="#FBECBC")
note_frame.config(bg="#FBECBC")
def button_check():
label_new_note.config(bg="#FBECBC")
subtitle_new_note.config(bg="#FBECBC")
note_frame.config(bg="#FBECBC")
def button_font():
label_new_note.config(bg="#FBECBC")
subtitle_new_note.config(bg="#FBECBC")
note_frame.config(bg="#FBECBC")
def button_lock():
label_new_note.config(bg="#FBECBC")
subtitle_new_note.config(bg="#FBECBC")
note_frame.config(bg="#FBECBC")
def button_note():
label_new_note.config(bg="#FBECBC")
subtitle_new_note.config(bg="#FBECBC")
note_frame.config(bg="#FBECBC")
def button_new_directory():
label_new_note.config(bg="#FBECBC")
subtitle_new_note.config(bg="#FBECBC")
note_frame.config(bg="#FBECBC")
# config window
window = Tk()
window.title("Notes")
window.minsize(746, 440)
window.maxsize(746, 440)
window.geometry("746x440+250+150")
window.config(bg="black")
# 3 big box
general_frame = Frame(window)
first_frame = Frame(general_frame)
second_frame = Frame(general_frame)
# config panedWindow
panedwindow2 = PanedWindow(second_frame, orient=VERTICAL, sashrelief=RAISED, bd=0)
panedwindow2.pack(fill=BOTH, expand=YES)
panedwindow = PanedWindow(first_frame, orient=HORIZONTAL, sashrelief=RAISED, bd=0)
panedwindow.pack(fill=BOTH, expand=YES)
frame1 = Frame(panedwindow, bg="#D9D9D9", width=165, height=400)
frame2 = Frame(panedwindow, bg="#fffaf6", width=175, height=400)
frame3 = Frame(panedwindow, bg="#fffaf6", width=375, height=400)
note_frame = Frame(frame2, bg="#FDE098", width=200, height=60)
second_frame1 = Frame(panedwindow2, bg="#D0D0D0", width=746, height=40)
panedwindow2.add(second_frame1)
panedwindow.add(frame1)
panedwindow.add(frame2)
panedwindow.add(frame3)
# config labels
label_new_note = Label(note_frame, bg="#FDE098", bd=0, font=("Helvetica", 20, "bold"), fg="black", text="New Note",
width=15)
subtitle_new_note = Label(note_frame, bg="#FDE098", bd=0, font=("Helvetica", 16), fg="#808080", text="Yesterday Unlock",
width=15)
label_note = Label(frame3, bg="#fffaf6", bd=0, font=("Helvetica", 10), fg="#808080", text="6 march 2021 16:03",
width=70)
label_note.pack()
# config text zone
text_zone = ScrolledText(frame3, bg="#fffaf6", bd=0, font=("Helvetica", 15), fg="black", width=70, height=400,
highlightthickness=0)
text_zone.pack()
text_zone.pack()
# config image buttons
img_delete = PhotoImage(file="Resource/Icon/delete.png")
img_lock = PhotoImage(file="Resource/Icon/lock.png")
img_write = PhotoImage(file="Resource/Icon/write.png")
img_font = PhotoImage(file="Resource/Icon/font.png")
img_check = PhotoImage(file="Resource/Icon/check.png")
img_add = PhotoImage(file="Resource/Icon/add.png")
# config buttons
note_button = Button(frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black",
width=200, height=30, text="All Notes", command=button_note)
note_button.pack()
delete_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15),
fg="black", width=40, height=40, image=img_delete, command=button_delete)
delete_button.pack(side=LEFT, padx=55)
write_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15),
fg="black", width=40, height=40, image=img_write, command=button_write)
write_button.pack(side=LEFT, padx=55)
check_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15),
fg="black", width=40, height=40, image=img_check, command=button_check)
check_button.pack(side=LEFT, padx=55)
font_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15),
fg="black", width=40, height=40, image=img_font, command=button_font)
font_button.pack(side=LEFT, padx=55)
lock_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15),
fg="black", width=40, height=40, image=img_lock, command=button_lock)
lock_button.pack(side=LEFT, padx=55)
new_directory_button = Button(frame1, compound=LEFT, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0,
font=("Helvetica", 15), fg="black", width=200, height=30, image=img_add,
text="New directory", command=button_new_directory)
new_directory_button.pack(side=BOTTOM)
# pack frames
second_frame.pack(expand=YES)
first_frame.pack(expand=YES)
general_frame.pack(expand=YES)
# install old note
def old_notes():
all_files = [f for f in listdir("note_resource/notes") if isfile(join("note_resource/notes", f))]
i = 0
i_2 = len(all_files) - 1
while i <= i_2:
file = all_files[i]
note_file = open("note_resource/notes/{}".format(file), "r")
read_note_file = note_file.readlines()
label_old_note = read_note_file[0]
subtitle_old_note_read = read_note_file[1]
for spllit_date_old_note in subtitle_old_note_read.split("."):
spllit_date_old_note_file = open("note_resource/split_date_old_note.txt", "a")
spllit_date_old_note_file.write(spllit_date_old_note + "\n")
spllit_date_old_note_file.close()
spllit_date_old_note_file = open("note_resource/split_date_old_note.txt", "r")
spllit_date_old_note_file_read = spllit_date_old_note_file.readlines()
spllit_date_old_note_file.close()
date_old_note_day = spllit_date_old_note_file_read[0]
date_old_note_month = spllit_date_old_note_file_read[1]
date_old_note_year = spllit_date_old_note_file_read[2]
year_open = opening_time.year - int(date_old_note_year)
month_open = opening_time.month - int(date_old_note_month)
day_open = opening_time.day - int(date_old_note_day)
if year_open == 0 and month_open == 0 and day_open == 0:
subtitle_old_note = "Today"
elif year_open == 0 and month_open == 0 and day_open == 1:
subtitle_old_note = "Yesterday"
else:
subtitle_old_note = subtitle_old_note_read
spllit_date_old_note_file = open("note_resource/split_date_old_note.txt", "w")
spllit_date_old_note_file.write("")
spllit_date_old_note_file.close()
note_frame = {}
note_frame[label_old_note] = Frame(frame2, bg="#FBECBC", width=200, height=60)
label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black",
text=label_old_note.strip(), width=15)
subtitle_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 16), fg="#808080",
text=subtitle_old_note.strip(), width=15)
label_new_note.pack()
subtitle_new_note.pack()
note_frame[label_old_note].pack()
i += 1
# call old_notes()
old_notes()
# run window
window.mainloop()
Le code n'est pas terminé.
Ce que je faire c'est de créé des frames différente pour chaque notes pour les contrôler indépendament et pouvoir clicker dessus pour les éditer. Le probleme c'est qu'en faisant comme j'ai fait il clone les "note_frame" et je peut donc plus les modifier ou interagir avec elle. Si tu as une solution (dictionnaire ou autre) je serais ravi.
Merci d'avance
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
16 mars 2021 à 18:25
16 mars 2021 à 18:25
cette ligne-ci est, de toute évidence, incorrecte:
que vient y faire
label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black", text=label_old_note.strip(), width=15)
que vient y faire
note_frame?
Rolement
>
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
16 mars 2021 à 19:38
16 mars 2021 à 19:38
Enfaite label_new_note est le titre de la note qu'on récupère et il vient s'inscrire dans note_frame qui est le rectangle jaune symbolisant la note le code fonctionne correctement mais le problème est que note_frame est cloner et donc incontrôlable.
Sinon vois-tu d'autres erreurs ou problème ?
Merci de prendre du temps pour moi
Sinon vois-tu d'autres erreurs ou problème ?
Merci de prendre du temps pour moi
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
>
Rolement
16 mars 2021 à 20:39
16 mars 2021 à 20:39
c'est amusant qua tu écrives "note_frame est cloner et donc incontrôlable".
alors que, hier, tu était content de la solution permettant de contrôler chacune des instances de note_frame.
je pense que tu te trompes quand tu écris "note_frame est le rectangle jaune".
regarde bien, quelle est l'instruction qui crée le rectangle jaune?
alors que, hier, tu était content de la solution permettant de contrôler chacune des instances de note_frame.
je pense que tu te trompes quand tu écris "note_frame est le rectangle jaune".
regarde bien, quelle est l'instruction qui crée le rectangle jaune?
Rolement
>
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
17 mars 2021 à 08:43
17 mars 2021 à 08:43
Enfaite je suis content de la solution mais il y a une erreur lorsque c'est le programme complet qui tourne. Le voici :
Je ne sais pas si tu arriveras à le faire marcher car il nécéssite des dossiers et des fichiers texte. Et j'ai vérifié c'est bien note_frame qui créé le réctangle jaune.
# import modules from tkinter import * from tkinter.scrolledtext import ScrolledText from tkmacosx import Button from tkinter import StringVar from datetime import * from os import listdir from os.path import isfile, join # recovery of the opening time of the app and stock opening_time = datetime.now() year = opening_time.year month = opening_time.month day = opening_time.day hour = opening_time.hour minute = opening_time.minute second = opening_time.second opening_time_file = open("note_resource/opening_time.txt", "w") opening_time_file.write(str(year)) opening_time_file.write("\n" + str(month)) opening_time_file.write("\n" + str(day)) opening_time_file.write("\n" + str(hour)) opening_time_file.write("\n" + str(minute)) opening_time_file.write("\n" + str(second)) opening_time_file.close() # config note class class Note: def __init__(self, label, subtitle, date_creation, close): self.label = label self.subtitle = subtitle self.date_creation = date_creation self.close = close # config function button def note_click(): label_new_note.config(bg="#FDE098") subtitle_new_note.config(bg="#FDE098") note_frame.config(bg="#FDE098") def button_write(): class PopUp(Tk): def __init__(self): Toplevel.__init__(self) Toplevel.withdraw(self) popup_new_note = Toplevel(self) popup_new_note.title("New Note") popup_new_note.geometry("+225+275") popup_new_note.config(bg="#fffaf6") popup_new_note.tkraise(self) self.mystring = StringVar(popup_new_note) new_note_entry = self.entry = Entry(popup_new_note, textvariable=self.mystring, bd=1, width=35, relief=RIDGE, bg="#fffaf6", highlightthickness=0) new_note_entry.pack(padx=5, pady=3) self.button = Button(popup_new_note, text="OK", command=self.entry_button) self.button.pack(side=BOTTOM) popup_new_note.grab_set() def entry_button(self): new_note_entry_value = self.mystring.get() PopUp.destroy(self) new_note_entry_file = open("note_resource/new_note_title.txt", "w") new_note_entry_file.write(new_note_entry_value) app.quit() app = PopUp() app.mainloop() new_note_entry_value_file = open("note_resource/new_note_title.txt", "r") new_note_entry_value_file_read = new_note_entry_value_file.readline() new_note_label = new_note_entry_value_file_read creation_date_all = datetime.now() creation_date_day = creation_date_all.day if creation_date_day < 10: creation_date_day = str(creation_date_day) creation_date_day = "0" + creation_date_day creation_date_month = creation_date_all.month if creation_date_month < 10: creation_date_month = str(creation_date_month) creation_date_month = "0" + creation_date_month creation_date_year = creation_date_all.year creation_date_year = str(creation_date_year) creation_date = "{}.{}.{}".format(creation_date_day, creation_date_month, creation_date_year) note = Note(new_note_label, "Today", creation_date, False) note_label = note.label note_subtitle = note.subtitle note_date_creation = str(note.date_creation) note_close = note.close new_note_file = open("note_resource/notes/note_{}.txt".format(note_label), "+w") new_note_file.write(note_label + "\n" + note_date_creation + "\n" + "false" + "\n" + "content") note_frame = {} note_frame[str(note_label)] = Frame(frame2, bg="#FBECBC", width=200, height=60) label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black", text=note_label, width=15) subtitle_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 16), fg="#808080", text=note_subtitle, width=15) label_new_note.pack() subtitle_new_note.pack() note_frame[str(note_label)].pack() def button_delete(): label_new_note.config(bg="#FBECBC") subtitle_new_note.config(bg="#FBECBC") note_frame.config(bg="#FBECBC") def button_check(): label_new_note.config(bg="#FBECBC") subtitle_new_note.config(bg="#FBECBC") note_frame.config(bg="#FBECBC") def button_font(): label_new_note.config(bg="#FBECBC") subtitle_new_note.config(bg="#FBECBC") note_frame.config(bg="#FBECBC") def button_lock(): label_new_note.config(bg="#FBECBC") subtitle_new_note.config(bg="#FBECBC") note_frame.config(bg="#FBECBC") def button_note(): label_new_note.config(bg="#FBECBC") subtitle_new_note.config(bg="#FBECBC") note_frame.config(bg="#FBECBC") def button_new_directory(): label_new_note.config(bg="#FBECBC") subtitle_new_note.config(bg="#FBECBC") note_frame.config(bg="#FBECBC") # config window window = Tk() window.title("Notes") window.minsize(746, 440) window.maxsize(746, 440) window.geometry("746x440+250+150") window.config(bg="black") # 3 big box general_frame = Frame(window) first_frame = Frame(general_frame) second_frame = Frame(general_frame) # config panedWindow panedwindow2 = PanedWindow(second_frame, orient=VERTICAL, sashrelief=RAISED, bd=0) panedwindow2.pack(fill=BOTH, expand=YES) panedwindow = PanedWindow(first_frame, orient=HORIZONTAL, sashrelief=RAISED, bd=0) panedwindow.pack(fill=BOTH, expand=YES) frame1 = Frame(panedwindow, bg="#D9D9D9", width=165, height=400) frame2 = Frame(panedwindow, bg="#fffaf6", width=175, height=400) frame3 = Frame(panedwindow, bg="#fffaf6", width=375, height=400) note_frame = Frame(frame2, bg="#FDE098", width=200, height=60) second_frame1 = Frame(panedwindow2, bg="#D0D0D0", width=746, height=40) panedwindow2.add(second_frame1) panedwindow.add(frame1) panedwindow.add(frame2) panedwindow.add(frame3) # config labels label_new_note = Label(note_frame, bg="#FDE098", bd=0, font=("Helvetica", 20, "bold"), fg="black", text="New Note", width=15) subtitle_new_note = Label(note_frame, bg="#FDE098", bd=0, font=("Helvetica", 16), fg="#808080", text="Yesterday Unlock", width=15) label_note = Label(frame3, bg="#fffaf6", bd=0, font=("Helvetica", 10), fg="#808080", text="6 march 2021 16:03", width=70) label_note.pack() # config text zone text_zone = ScrolledText(frame3, bg="#fffaf6", bd=0, font=("Helvetica", 15), fg="black", width=70, height=400, highlightthickness=0) text_zone.pack() text_zone.pack() # config image buttons img_delete = PhotoImage(file="Resource/Icon/delete.png") img_lock = PhotoImage(file="Resource/Icon/lock.png") img_write = PhotoImage(file="Resource/Icon/write.png") img_font = PhotoImage(file="Resource/Icon/font.png") img_check = PhotoImage(file="Resource/Icon/check.png") img_add = PhotoImage(file="Resource/Icon/add.png") # config buttons note_button = Button(frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=200, height=30, text="All Notes", command=button_note) note_button.pack() delete_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=40, height=40, image=img_delete, command=button_delete) delete_button.pack(side=LEFT, padx=55) write_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=40, height=40, image=img_write, command=button_write) write_button.pack(side=LEFT, padx=55) check_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=40, height=40, image=img_check, command=button_check) check_button.pack(side=LEFT, padx=55) font_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=40, height=40, image=img_font, command=button_font) font_button.pack(side=LEFT, padx=55) lock_button = Button(second_frame1, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=40, height=40, image=img_lock, command=button_lock) lock_button.pack(side=LEFT, padx=55) new_directory_button = Button(frame1, compound=LEFT, activeforeground="#D9D9D9", bg="#D9D9D9", borderless=0, font=("Helvetica", 15), fg="black", width=200, height=30, image=img_add, text="New directory", command=button_new_directory) new_directory_button.pack(side=BOTTOM) # pack frames second_frame.pack(expand=YES) first_frame.pack(expand=YES) general_frame.pack(expand=YES) # install old note def old_notes(): all_files = [f for f in listdir("note_resource/notes") if isfile(join("note_resource/notes", f))] i = 0 i_2 = len(all_files) - 1 while i <= i_2: file = all_files[i] note_file = open("note_resource/notes/{}".format(file), "r") read_note_file = note_file.readlines() label_old_note = read_note_file[0] subtitle_old_note_read = read_note_file[1] for spllit_date_old_note in subtitle_old_note_read.split("."): spllit_date_old_note_file = open("note_resource/split_date_old_note.txt", "a") spllit_date_old_note_file.write(spllit_date_old_note + "\n") spllit_date_old_note_file.close() spllit_date_old_note_file = open("note_resource/split_date_old_note.txt", "r") spllit_date_old_note_file_read = spllit_date_old_note_file.readlines() spllit_date_old_note_file.close() date_old_note_day = spllit_date_old_note_file_read[0] date_old_note_month = spllit_date_old_note_file_read[1] date_old_note_year = spllit_date_old_note_file_read[2] year_open = opening_time.year - int(date_old_note_year) month_open = opening_time.month - int(date_old_note_month) day_open = opening_time.day - int(date_old_note_day) if year_open == 0 and month_open == 0 and day_open == 0: subtitle_old_note = "Today" elif year_open == 0 and month_open == 0 and day_open == 1: subtitle_old_note = "Yesterday" else: subtitle_old_note = subtitle_old_note_read spllit_date_old_note_file = open("note_resource/split_date_old_note.txt", "w") spllit_date_old_note_file.write("") spllit_date_old_note_file.close() note_frame = {} note_frame[label_old_note] = Frame(frame2, bg="#FBECBC", width=200, height=60) label_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 20, "bold"), fg="black", text=label_old_note.strip(), width=15) subtitle_new_note = Label(note_frame, bg="#FBECBC", bd=0, font=("Helvetica", 16), fg="#808080", text=subtitle_old_note.strip(), width=15) label_new_note.pack() subtitle_new_note.pack() note_frame[label_old_note].pack() i += 1 # call old_notes() old_notes() # run window window.mainloop()
Je ne sais pas si tu arriveras à le faire marcher car il nécéssite des dossiers et des fichiers texte. Et j'ai vérifié c'est bien note_frame qui créé le réctangle jaune.
yg_be
Messages postés
23526
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
14 avril 2025
1 577
>
Rolement
17 mars 2021 à 11:52
17 mars 2021 à 11:52
ton programme simplifié fonctionne bien chez moi, après avoir corrigé ton utilisation incorrecte de note_frame.
je pense que tu te trompes quand tu écris "note_frame crée le réctangle jaune".
à quelle ligne de code le rectangle est-il créé?
quelle est l'instruction qui se trouve dans cette ligne?
je pense que tu te trompes quand tu écris "note_frame crée le réctangle jaune".
à quelle ligne de code le rectangle est-il créé?
quelle est l'instruction qui se trouve dans cette ligne?
Phil_1857
Messages postés
1872
Date d'inscription
lundi 23 mars 2020
Statut
Membre
Dernière intervention
28 février 2024
168
16 mars 2021 à 18:21
16 mars 2021 à 18:21
Bonjour
si tu utilisait les balises de code Python, visuellement ton code ressemblerait à ça
(avec la coloration syntaxique) :
si tu utilisait les balises de code Python, visuellement ton code ressemblerait à ça
(avec la coloration syntaxique) :
def test(): print('test') test()
15 mars 2021 à 17:53