1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| from tkinter import *
import copy
#######################################
# corps principal du programme :
class FenetreUn (Frame):
def __init__ (self, master) :
"""Constructeur de notre classe"""
Frame.__init__(self, master)
self ['bg']="azure3"
self.pack()
self.button = Button (self, width = 12, height = 2,
text ="ajouter", command = self.ajouter, bg = "SeaGreen1")
self.button.pack()
def ajouter (self):
ma_fenetre = FenetreDeux
ma_fenetre.ajouter_element2 ( "bonjour")
#cette methode devrait ajouter une ligne a la listbox_designation
class FenetreDeux (Frame):
def __init__ (self, master) :
"""Constructeur de notre classe"""
Frame.__init__(self, master)
self ['bg']="azure3"
self.pack()
self.listbox_designation = Listbox (self, width = 15, height = 18, bd
= 0, bg = "gray95", highlightcolor = "gray95", activestyle = "none")
self.listbox_designation.pack()
self.listbox_designation.insert (END, "designation")
self.listbox_designation.insert (END, "une de plus")
self.ajouter_element ("3 ème ligne")
def ajouter_element (self, designation):
"""Méthode pour ajouter une ligne a la listbox"""
self.listbox_designation.insert (END, designation)
def ajouter_element2 (designation):
print (designation)
class Application(Frame):
"""
Fenêtre principale de l'application
"""
def __init__(self):
"""Constructeur de notre classe"""
Frame.__init__(self)
self.master['bg']="azure3"
self.master.title("Fenêtre principale")
self.master.resizable(width=False, height=False)
# Fenetre non resizable
self.master.geometry("950x550+0+0")
self ['bg'] = "azure3"
self.pack()
# frame_1
self.frame_1 = Frame(self)
self.frame_1.grid (row = 1, column = 1, padx=30, pady=30)
self.ma_fenetre_1 = FenetreUn(self.frame_1)
# frame_2
self.frame_2 = Frame(self)
self.frame_2.grid (row = 1,column = 2, padx=30, pady=30)
self.ma_fenetre_2 = FenetreDeux(self.frame_2)
if __name__ == "__main__":
Application().mainloop() |
Partager