473,385 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading which button is pressed

I am trying to write a python script to help some deaf people. They have a list of sign language songs which are in m4v format.
I have a raspberry pi and a monitor which I can give them.
My intention is to provide a gui with all the song numbers on buttons so they just click the mouse on one and the video plays then returns.
I know that I can launch omxplayer with the file as a parameter.
I am trying to develop the code on my linux laptop and then transfer it to the raspberry pi along with all the songs >>> There are 152 of them <<<
That is where my problem comes from.
I have the following code ( just the relevant snippets):
Expand|Select|Wrap|Line Numbers
  1. def play_song(p):
  2.     i=p; k=int(i)
  3.     if k>0:
  4.         if k<136:
  5.             starter="home/norman//Downloads/bsl/sn_"
  6.         else:
  7.             starter="snnw_"
  8.         if k<156:
  9.             stp=str(k)
  10.             if len(stp)<2:
  11.                 stp="0"+stp
  12.                 if len(stp)<3:
  13.                     stp=" " + stp
  14.     song2play=starter+ stp +"_r480P.m4v"
  15.     print song2play
  16.  
  17. # generate the buttons
  18. for x in range(1,9):
  19.     for y in range(1,20):
  20.         txt=str(q)
  21.         j=int(txt)
  22.         myname="button" + str(x*y)
  23.         myname = Button(frame2,text=txt, font=TF, width=3, command = lambda: play_song(txt))
  24.         myname.grid(row = x+2, column=y+1)
  25.         q+=1
  26.  
I have tried various ways of passing the correct song number to the function but whatever I try I get the same problem or lots of errors with other versions I have tried.
I get the same file name generated:
snnw_152_r480P.m4v
whichever button I click. Can it be done this way or do I have to create the buttons some other way
Sep 18 '16 #1
3 1072
It's olay, thanks got it sorted. Must have my dumb head on tonight.Just altered a lit bit of the code:
Expand|Select|Wrap|Line Numbers
  1. def play_song(event):
  2.     p = event.widget['text']
  3.     k=int(p)
  4.  
and
Expand|Select|Wrap|Line Numbers
  1.         myname = Button(frame2,text=txt, font=TF, width=3)
  2.         myname.bind('<Button-1>', play_song)
  3.  
So now it does work.
Sep 18 '16 #2
dwblas
626 Expert 512MB
What happens when k > 155? You can also use partial to pass the number to the function
Expand|Select|Wrap|Line Numbers
  1. from functools import partial
  2.  
  3.         myname = Button(frame2,text=txt, font=TF, width=3, command = partial(play_song, txt))  
Note that bind sends an event to the function, while "command" does not.
Sep 18 '16 #3
Thanks dwblas, didn't know about partial.
I don't think k can be higher than 155 in this situation unless I am missing something?
Sep 19 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: M | last post by:
i have a form which i would like to input different "action" url depending on the button that was clicked. is there a way that javascript can prefill a defined action based on the button...
0
by: Earl Teigrob | last post by:
This is an odd one. When I first display a thumbnail page and the user clicks one of the image links, the user goes to the correct page. If the user uses my application back button, (called...
3
by: Mel | last post by:
Hi, Is there any way I can force to change button background colour when toggle button is checked? Just like button change its background colour when mouseover in MS Visual Studio.NET. I hope I...
1
by: Ed Sutton | last post by:
<Newbie> How can I get arguments, and build a query URL, before a button is pressed? I have a text box to enter a serial number. When the search button is pressed, I wish append the serial...
4
by: OutdoorGuy | last post by:
Greetings, I have the following code in a VB.NET Windows application and was wondering if there is any way to determine whether or not the user pressed the "Cancel" button on the...
1
by: thewickedman | last post by:
Hi, I try to open new OpenOffice document (writer), But I am getting the exception FRM 40735:WHEN-BUTTON-PRESSED Trigger Raised unhandled Exception ORA - 305500 Please help me to resolve...
2
by: thesti | last post by:
hi, this might be a programming logic problem the scenario is, i have a label with imageIcon and two buttons, A and B. the label (with imageIcon) is representing the value of a randomed...
2
by: F159753 | last post by:
Hi, I have 2 text box and a "search " button. I would like to check if the text boxes are empty when the search button has been pressed. How should I do that? Regards, FF
5
by: F159753 | last post by:
Hi, I have two text box and an image submit button. how should I know if the button has been pressed in a JavaScript? Regards, FF
8
by: jodleren | last post by:
Hi It is late and I am tired. I cannot remember how to check which of my buttons on the form was pressed. There are all submit's. Like echo "P=".$_POST; // and eventually using isset() ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.