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
| # fenêtre simpliste
from tkinter import *
canvas = None
def create_canvas():
global canvas
if not canvas:
canvas = Canvas(fen1,bg='dark grey',height=200,width=200)
canvas.pack(side=RIGHT)
def destroy_canvas():
global canvas
if canvas:
canvas.destroy()
canvas = None
# Création du widget principal ("maître") :
fen1 = Tk()
# création des widgets "esclaves" :
tex1 = Label(fen1, text='Bonjour tout le monde !', fg='red')
tex1.pack()
## can1 = Canvas(fen1,bg='dark grey',height=200,width=200)
## can1.pack(side=RIGHT)
create_canvas()
bou1 = Button(fen1, text='Canevas Destroy', command = destroy_canvas)
bou1.pack()
bou2 = Button(fen1, text='Quitter', command = fen1.destroy)
bou2.pack(side=BOTTOM)
bou3 = Button(fen1, text='Canevas Create', command = create_canvas)
bou3.pack(side=LEFT)
# démarrage du réceptionnaire d'événements
fen1.mainloop() |
Partager