Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
python:interface_graphique_tkinter:start [2019/10/12 14:19] – créée physix | python:interface_graphique_tkinter:start [2020/07/24 03:31] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Interface graphique Tkinter ====== | ====== Interface graphique Tkinter ====== | ||
- | ===== Hello world ===== | + | [[https:// |
+ | |||
+ | [[https:// | ||
+ | |||
+ | ===== Exemples ===== | ||
+ | |||
+ | ==== Hello world ==== | ||
+ | |||
+ | <code python> | ||
+ | from tkinter import * | ||
+ | |||
+ | fenetre = Tk() | ||
+ | |||
+ | texte1 = Label(fenetre, | ||
+ | texte1.pack() | ||
+ | |||
+ | bouton1 = Button(fenetre, | ||
+ | bouton1.pack() | ||
+ | |||
+ | fenetre.mainloop() | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== Calculatrice ==== | ||
+ | |||
+ | <code python> | ||
+ | from tkinter import * | ||
+ | from math import * | ||
+ | |||
+ | # définition de l' | ||
+ | # la touche " | ||
+ | |||
+ | x = 10 | ||
+ | |||
+ | def evaluer(event): | ||
+ | chaine.configure(text = " | ||
+ | |||
+ | # ----- Programme principal : ----- | ||
+ | fenetre = Tk() | ||
+ | entree = Entry(fenetre) | ||
+ | entree.bind("< | ||
+ | chaine = Label(fenetre) | ||
+ | entree.pack() | ||
+ | chaine.pack() | ||
+ | |||
+ | fenetre.mainloop() | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== Les classes de tkinter ===== | ||
+ | |||
+ | |**// | ||
+ | |Button| | ||
+ | |Canvas| | ||
+ | |Checkbutton| | ||
+ | |Entry| | ||
+ | |Frame| | ||
+ | |Label| | ||
+ | |Listbox| | ||
+ | |Menu| | ||
+ | |Menubutton| | ||
+ | |Message| | ||
+ | |Radiobutton| | ||
+ | |Scale| | ||
+ | |Scrollbar| | ||
+ | |Text| | ||
+ | |Toplevel| | ||
+ | |||
+ | ==== Button ==== | ||
+ | |||
+ | <code python> | ||
+ | |||
+ | from tkinter import * | ||
+ | |||
+ | fenetre = Tk() | ||
+ | |||
+ | bouton1 = Button(fenetre, | ||
+ | bouton1.pack() | ||
+ | |||
+ | fenetre.mainloop() | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== Canvas ==== | ||
+ | |||
+ | <code python> | ||
+ | from tkinter import * | ||
+ | |||
+ | fenetre = Tk() | ||
+ | |||
+ | canvas = Canvas(fenetre, | ||
+ | ligne1 = canvas.create_line(75, | ||
+ | ligne2 = canvas.create_line(0, | ||
+ | txt = canvas.create_text(75, | ||
+ | canvas.pack() | ||
+ | |||
+ | fenetre.mainloop() | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Autres éléments : | ||
+ | |||
+ | <code python> | ||
+ | create_arc() | ||
+ | create_bitmap() | ||
+ | create_image() | ||
+ | create_line() | ||
+ | create_oval() | ||
+ | create_polygon() | ||
+ | create_rectangle() | ||
+ | create_text() | ||
+ | create_window() | ||
+ | |||
+ | </ | ||
+ | |||
+ | Pour changer les coordonnées d'un élément : | ||
+ | |||
+ | <code python> | ||
+ | canvas.coords(élément, | ||
+ | |||
+ | </ | ||
+ | |||
+ | Pour supprimer un élément : | ||
+ | |||
+ | <code python> | ||
+ | canvas.delete(élément) | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Checkbutton ==== | ||
+ | |||
+ | <code python> | ||
+ | from tkinter import * | ||
+ | |||
+ | fenetre = Tk() | ||
+ | |||
+ | bouton = Checkbutton(fenetre, | ||
+ | bouton.pack() | ||
+ | |||
+ | fenetre.mainloop() | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | \\ | ||