Skip to content

Instantly share code, notes, and snippets.

@Franck1333
Created September 28, 2018 15:28
Show Gist options
  • Save Franck1333/2815663120ef980c2be6290b2b3611b9 to your computer and use it in GitHub Desktop.
Save Franck1333/2815663120ef980c2be6290b2b3611b9 to your computer and use it in GitHub Desktop.
Get a child window with Tkinter/Python (Meteo Example)
#AIDE : https://www.daniweb.com/programming/software-development/threads/39554/how-to-opening-a-new-window-on-clicking-menu-item
# display message in a child window
from Tkinter import *
def messageWindow():
# create child window
win = Toplevel()
# display message
message = "This is the child window"
Label(win, text=message).pack()
# quit child window and return to root window
# the button is optional here, simply use the corner x of the child window
Button(win, text='OK', command=win.destroy).pack()
# create root window
root = Tk()
# put a button on it, or a menu
Button(root, text='Bring up Message', command=messageWindow).pack()
# start event-loop
root.mainloop()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Aides : http://apprendre-python.com/page-tkinter-interface-graphique-python-tutoriel
#Aides : http://www.fil.univ-lille1.fr/~marvie/python/chapitre6.html
#AIDES : https://www.daniweb.com/programming/software-development/threads/39554/how-to-opening-a-new-window-on-clicking-menu-item
import os
import sys
from Tkinter import *
fenetre = Tk() #Creation d'une Fenetre TK appeler "fenetre"
#------------------------------------------------------------------------------
#Cette fonction permet d'avoir une fenetre ENFANT pour l'affichage du Menu Meteo
def FenetreMeteo():
# create child window
meteo = Toplevel()
# display message
PrevisionMeteo = "Aujourd'hui il fait 22° Degree Celcius a Angers, France"
Label(meteo, text=PrevisionMeteo).pack()
# quit child window and return to root window
# the button is optional here, simply use the corner x of the child window
Button(meteo, text="Compris!", command=meteo.destroy).pack()
#------------------------------------------------------------------------------
#----------------------------------------------------------------------
label = Label(fenetre, text="Heure et Minute Actuel ici")#.grid(row=0, column=5)
label.pack()
#----------------------------------------------------------------------
#----------------------------------------------------------------------
#Bouton Meteo permettant d'utilisé la fonction "FenetreMeteo()"
bouton_meteo=Button(fenetre, text="Meteo", command=FenetreMeteo)#.grid(row=3, column=0) #<--COMMAND
bouton_meteo.pack()
bouton_food=Button(fenetre, text="Quoi Manger ?", command=fenetre.quit)#.grid(row=3, column=10)
bouton_food.pack()
bouton_music=Button(fenetre, text="Quoi ecouter ?", command=fenetre.quit)#.grid(row=4, column=10)
bouton_music.pack()
bouton_place=Button(fenetre, text="Ou aller ?", command=fenetre.quit)#.grid(row=5, column=10)
bouton_place.pack()
bouton=Button(fenetre, text="Fermer", command=fenetre.destroy )#.grid(row=13, column=13)
bouton.pack()
#----------------------------------------------------------------------
#----------------------------------------------------------------------
fenetre.mainloop()
#----------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment