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
|
from tkinter import *
from os import system
from random import shuffle
class Clavier(Frame):
"""Notre fenêtre principale.
Tous les widgets sont stockés comme attributs de cette fenêtre."""
def __init__(self, fenetre, **kwargs):
Frame.__init__(self, fenetre, **kwargs)
self.place(height=280,width=420,x=0,y=0)
self.nb_clic = 0
self.frame1 = Frame(self,height=320,width=240,relief='raised',borderwidth=3)
self.frame1.place(x=1,y=1)
# Création des boutons test
self.message = Label(self.frame1, text="Entrez le code")
self.message.place(width=200,x=5,y=290)
self.bouton_quitter = Button(self, text="Quitter",width=10, command=self.quit)
self.bouton_quitter.place(x=370,y=285,bordermode=INSIDE)
self.bouton_allumer=Button(self,text="ON",width=3,height=1,command=self.allumer)
self.bouton_allumer.place(x=250,y=285)
self.bouton_eteindre=Button(self,text="OFF",width=3,height=1,command=self.eteindre)
self.bouton_eteindre.place(x=310,y=285)
self.TextCode = Label(self.frame1,text="")
self.TextCode.place(x=4,y=290)
self.pack()
self.clavier()
#Creation du Frame Clavier
def clavier(self):""" je creer les 9 boutons du clavier"""
listX = [4,80,156]
shuffle(listX)
listY = [3,74,144]
shuffle(listY)
index=1
for i in listX:
for j in listY:
self.bouton = Button(self.frame1,text=index,width=5,height=4,command=self.cliquer(index))
self.bouton.place(x=i,y=j)
index +=1
""" les boutons 0, C et OK restent à la même place"""
self.bouton_0 = Button(self.frame1,text="0",width=5,height=4,command=self.cliquer(0))
self.bouton_0.place(x=4,y=215)
self.bouton_C = Button(self.frame1,text="C",width=5,height=4,command=self.cliquer("C"))
self.bouton_C.place(x=80,y=215)
self.bouton_OK = Button(self.frame1,text="OK",width=5,height=4,command=self.remake)
self.bouton_OK.place(x=156,y=215)
self.pack()
def cliquer(frame1,mavaleur):
"""Il y a eu un clic sur le bouton.
On change la valeur du label TextCode."""
def majText():
"""je limite le code à 8 chiffres"""
if len(frame1.TextCode["text"]) < 8:
if mavaleur in range(10):
frame1.TextCode["text"] = "{}{}".format(frame1.TextCode["text"],mavaleur)
if mavaleur == "C":"""je vide le code saisi"""
frame1.TextCode["text"] = ""
return majText
def allumer(self):
"""action wget json allumer lumiere salon input_0"""
system('wget --no-check-certificate --post-file set_state_on.json --output-document result.json https://192.168.1.1/api.php')
def eteindre(self):
"""action wget json eteindre lumiere salon input_0"""
system('wget --no-check-certificate --post-file set_state_off.json --output-document result.json https://192.168.1.1/api.php')
def remake(frame1):"""je voudrais effacer et recreer les boutons du clavier avec une nouvelle disposition"""
for Button in frame1:""" NE FONCTIONNE PAS """
Bouton.destroy()
self.clavier() |
Partager