Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How many times it was pressed the button
#1
Hello,
I have a few buttons and I want to understand how many times they push these buttons, can it write in a file and it send via email this file every day.Is it possible?
Thank you
Quote
#2
Yes, it is possible.
The flow and techniques involved will depend on what GUI you are using, but in general something like:
1. On program start, read the file, which contains date and number info
2. If the date is new, transmit yesterday's total.
3. Record the presses
4. On close, write the totals back to the file (adding prior totals if this is not a new day)
chano likes this post
Quote
#3
You can even use real switches with Raspberry Pi.
In this case you'll find many tutorials for Python.
In the case of real switches the bounce time is very important.

I guess you would it do with a GUI.
Tkinter is shipped with Python.


from tkinter import (
    Tk, Button, Label, IntVar,
)


def count():
    variable.set(variable.get() + 1)


root = Tk()
variable = IntVar(root)

Button(root, text='Push Counter', command=count).pack()
Label(root, textvariable=variable).pack()
Button(root, text='Exit', command=root.destroy).pack()

root.mainloop()
You can extend the code with one function to save the data in a file.
The command is a callable function, which is called, when the button was pressed.
For example the exit button calls root.destroy() which kills all children and the root (GUI closes).
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Quote
#4
Hello,
This is a sample button,i am a beginner in python and tkinter,can you help me with this code,if is possible i want like push button 10 times it write in file and send to my email,every day,this is mashine for water and i want to know how much is pushing the buttons,i have two buttons for warm and cool water.if you can help me и will be very grateful.

import tkinter as tk
from tkinter import *
import smtplib
from tkinter import Tk, Toplevel, Button
import RPi.GPIO as GPIO
import time
import tkinter.ttk as ttk
from tkinter.ttk import Progressbar, Style, Button
 
 
 
 

 
master1 =Toplevel()
master3 =Toplevel()
 
 
##################################right
 
master1.minsize(150,150+170+170)
master1.geometry("185x1000+0+0")
master1.configure(background="black",)
master1.title("2")
master1.overrideredirect(True)
#################################left
  
 
master3.label = tk.Label(master3, text='this is OK')
master3.label.pack()
 
 
 
def text_1_2():
    b2()
    nadpisok()
   ##########################
 
     
def nadpisok():
    print('Button clicked')
    master3.label['text'] = 'please wait'
    master3.button['state'] = 'disabled'
    master3.after(3000, master.delayed_textok)
    
     
def delayed_textok():
    master3.label['text'] = 'this is OK'
    master3.button['state'] = 'normal'
    master3.after(3000, master.finhished)
 
      
 
 
###########################################
GPIO.setwarnings(False)
 
    
#########################################
def b2():
        GPIO.setmode(GPIO.BCM)
        RELAIS_2_GPIO = 10
        GPIO.setup(RELAIS_2_GPIO, GPIO.OUT)
        GPIO.output(RELAIS_2_GPIO, GPIO.HIGH)
        time.sleep(0.35)
        GPIO.output(RELAIS_2_GPIO, GPIO.LOW)
        time.sleep(0.35)
#########################################
 
 
image2 = tk.PhotoImage(file="")
b = button = tk.Button(master1,image=image2, height=80, width=160,background="red",font="0",bd=10,fg="black",command= text_1_2)
b.place(x = 0, y = 120)
label2=Label(master1,text="",height=0, width=0,bg="#100C19",font="Times 13 underline",fg="white",relief="solid",bd=0).place(x=0,y=200)
#########################
 
master.mainloop()
GPIO.cleanup()

probably it is
pretty complex code..
Quote
#5
(Aug-13-2019, 02:54 PM)jefsummers Wrote: Yes, it is possible. The flow and techniques involved will depend on what GUI you are using, but in general something like: 1. On program start, read the file, which contains date and number info 2. If the date is new, transmit yesterday's total. 3. Record the presses 4. On close, write the totals back to the file (adding prior totals if this is not a new day)

this is quite difficult for me..
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Subtacting times Confused 2 392 Apr-10-2019, 05:13 PM
Last Post: nilamo
  [split] Calculate Times dhodgens 3 304 Mar-03-2019, 09:30 PM
Last Post: micseydel
  times greater number than the previous rhai 4 620 Oct-08-2018, 03:27 AM
Last Post: woooee
  Adding and Removing coins to match Coin Bag Total infinite times Strayfe 8 912 Sep-11-2018, 07:30 PM
Last Post: gruntfutuk
  Find how many times a user played an artist and how many times disruptfwd8 1 487 May-04-2018, 08:32 AM
Last Post: killerrex
  Search for Player ID and return games played and number of times disruptfwd8 3 666 May-03-2018, 06:45 PM
Last Post: disruptfwd8
  How many times does it fit? help please skriff 2 1,174 Sep-12-2017, 11:53 AM
Last Post: Sagar
  The int that appears an odd number of times. MeeranRizvi 6 2,175 Dec-30-2016, 09:54 AM
Last Post: wavic

Forum Jump:


Users browsing this thread: 1 Guest(s)