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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| from tkinter import *
class Bouton(Button):
def __init__(self, boss, **Arguments):
Button.__init__(self, boss, fg='white', bg='dark green',
font ='Times 14 bold italic', activebackground ="red",
activeforeground ="yellow", **Arguments)
class Fenetre_Secondaire(Toplevel):
def __init__(self):
Toplevel.__init__(self)
# on crée un Canvas....
self.can = Canvas(self, bg='ivory')
self.can.pack(padx=30, pady=30)
self.overrideredirect(1) # => fenêtre sans bordure ni bandeau
# ... et on y affiche une image
self.img = PhotoImage(file='smiley2.gif')
self.can.create_image(250, 150, image=self.img)
class Boite(Frame):
def __init__(self, Boss, flech=[0], orient="Vertical", valeur=150):
Frame.__init__(self, Boss, bg ="khaki")
if orient=='Vertical':
Button(self, text='^', width=5, command=self.BoutonVerticalSup).pack()
self.valeur = valeur
print (valeur , " + ", self.valeur)
self.lab = Label(self, text=self.valeur, bg='ivory', width=5)
self.lab.pack(side=TOP)
self.lab.configure(text = self.valeur)
Button(self, text='v', width=5, command=self.BoutonVerticalInf).pack()
else:
Button(self, text='<', width=5, command=self.BoutonHorizontalInf).pack(side=LEFT)
self.valeur = valeur
print (valeur , " + ", self.valeur)
self.lab = Label(self, text=self.valeur, bg='ivory', width=5)
self.lab.pack(side=LEFT)
self.lab.configure(text = self.valeur)
Button(self, text='>', width=5, command=self.BoutonHorizontalSup).pack(side=RIGHT)
def BoutonVerticalSup(self):
self.valeur = self.valeur+10
self.lab.configure(text = self.valeur)
def BoutonVerticalInf(self):
self.valeur = self.valeur-10
self.lab.configure(text = self.valeur)
def BoutonHorizontalSup(self):
self.valeur = self.valeur+10
self.lab.configure(text = self.valeur)
def BoutonHorizontalInf(self):
self.valeur = self.valeur-10
self.lab.configure(text = self.valeur)
class Fen_Controle(Toplevel):
def __init__(self):
Toplevel.__init__(self, bg ="khaki")
# Contrôle Horizontal
fleches = ['<', '>']
self.ControleHorizontal = Boite(self, flech=fleches, orient='Horizontal', valeur=150).pack(padx=5, pady=10)
# Contrôle Verticale
fleches = ['^', 'v']
self.ControleVertical = Boite(self, flech=fleches, orient='Vertical', valeur=150).pack(padx=5, pady=10)
# Affichage des modifications du Canvas de la fenêtre secondaire
Bouton(self, text='Dimensionner le canvas', command=self.Dimensionner_Canvas).pack(padx=10, pady=10)
def Dimensionner_Canvas(self):
print(self.ControleHorizontal)
print(self.ControleVertical)
class Application(Frame):
def __init__(self, boss):
Frame.__init__(self, boss, bg='cadet blue', width=400, height=300)
self.boss = boss
self.fra = Frame(self, bg='cadet blue')
self.fra.pack(side=BOTTOM, pady=5)
Bouton(self.fra, text='Top1', command=self.Creer_Fen).pack(side=LEFT, padx=1, pady=2)
Bouton(self.fra, text='Top2', command=self.Redim_Fen).pack(side=LEFT, padx=1, pady=2)
Bouton(self.fra, text='Quitter', command=self.Quitter).pack(side=RIGHT, padx=1, pady=2)
self.pack(fill=BOTH, expand=Y,side=BOTTOM)
self.pack_propagate(0)
def Creer_Fen(self):
Fenetre_Secondaire()
def Redim_Fen(self):
Fen_Controle()
def Quitter(self):
self.boss.destroy()
# --- Programme Principal ---
fen = Tk()
Application(fen).mainloop() |
Partager