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
| #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
import sys
from Tkinter import *
import Tkinter
import time
import threading
###############################################################################
class WateringThread(threading.Thread): # Thread pour ne pas freezer l'interface
def __init__(self):
threading.Thread.__init__(self)
self.encore = True
def run(self):
print "WateringThread se lance et change la valeur du pin"
time.sleep(1)
#if Commandes.Radioarrosage.get() == 3: # si je n'ai pas fait "On" ou "Off"
# print "je peux faire passer la pin à 0 et éteindre"
def stop(self):
print "WateringThread rechange le pin"
self.encore == False
###############################################################################
class Commandes (Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Commandes")
self.Radioarrosage = IntVar()
self.RadioarrosageOn = Radiobutton(self, text='\non\n',font=('bold'), variable= self.Radioarrosage, value=1, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchOnArrosage )
self.RadioarrosageOff = Radiobutton(self, text='\noff\n',font=('bold'), variable= self.Radioarrosage, value=2, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchOffArrosage )
self.RadioarrosageCinqMin = Radiobutton(self, text='\ntimer\n', font=('bold'),variable=self.Radioarrosage, value=3, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchCinqMinArrosage)
self.RadioarrosageOn.grid(column=6,row=11,columnspan=2,sticky='EW')
self.RadioarrosageOff.grid(column=8,row=11,columnspan=2,sticky='EW')
self.RadioarrosageCinqMin.grid(column=10,row=11,columnspan=2,sticky='EW')
def SwitchOnArrosage(self):
self.RadioarrosageOn.configure(selectcolor='red')
print self.Radioarrosage.get()
print "j'allume"
def SwitchOffArrosage(self):
self.RadioarrosageOff.configure(selectcolor='red')
print self.Radioarrosage.get()
print "j'éteins"
def SwitchCinqMinArrosage(self):
self.RadioarrosageCinqMin.configure(selectcolor='red')
self.RadioarrosageOn.deselect()
self.RadioarrosageOff.deselect()
print self.Radioarrosage.get()
if all(type(i) != WateringThread for i in threading.enumerate()): # si je n'ai pas encore lancé mon thread, je le lance
WT=WateringThread()
WT.start()
###############################################################################
#if __name__ == '__main__':
Interface = Commandes()
Interface.title('Menu')
Interface.mainloop() |
Partager