While working on a simple little timer I was creating to simultaneously help me learn more about Python and to help me keep on schedule with my schoolwork; I decided to add a little tune to let me know when your time was up. However, after using the following snippet of code to program each individual note:
winsound.Beep(Freq, Dur)
I realized that whenever I actually played the little song, an odd clicking sound happened between each note. Does anyone know what's going on? Should I use a different expression? Am I just losing my mind?
Edit: Since posting this, I realized what the issue is, the program is waiting about a sixteenth of second in between playing each note. So I'd like to ask another question (any answers relating to the others would still be appreciated), namely, how can I make it not wait in between the notes.
import winsound
winsound.Beep(262,500)
winsound.Beep(277,500)
winsound.Beep(294,500)
winsound.Beep(311,500)
winsound.Beep(330,500)
winsound.Beep(349,500)
winsound.Beep(370,500)
winsound.Beep(392,500)
winsound.Beep(415,500)
winsound.Beep(440,500)
winsound.Beep(466,500)
winsound.Beep(493,500)
winsound.Beep(523,500)
All the above code does is play a simple chromatic scale from middle c to c2, but once one runs it, one would immediately see what Im talking about
Related
I am pretty much a beginner at Python and code altogether. I have a raspberry pi to mess around on and I recently got a Trilobot.
I'm trying to set it up so I can control it with a keyboard. I decided to use turtle and have been using things like the code below. I want to be able to go forward and right, but I don't know how to do both of them at the same time by holding w and d.
def forward():
Bot.forward()
wn.onkeypress(forward, “w”)
I don't know if any of that made sense. If it didn't, I'll gladly explain myself to get an answer.
Hello I want to run a function that puts some random dots to paint but I want to make this thing for several times so ı need a multiprocessor but I doubt about it because of that, I use pyautogui to put dots to random coordinates of the paint table. So, I wonder that if I use a multiprocessor, will it just get broke or will it just work fine?
Thanks already to whoever answers this question!
Note : I am pretty surprised I did not see that same question on this forum, if I missed it please link in comment :)
I am writing a bot in python that would eventually be able to play a browser-based video game (HTML5 canvas game, not Flash). In order to do that I need to simulate the keyboard events from the python code.
I thought pyautogui would do the work, but unfortunately it seems the only way to repeat a key is to do pyautogui.press(key) in a loop, and it is not good at all for playing games as the move is not smooth at all.
I found some solutions for Windows, but I need a solution for macOSX.
To cut a long story short, I've been doing an interactive GUI (tkinter) word-game program for school. At first, everything went smoothly, but having finished the code, it has started to behave in unexpected ways when I run it. Some dialog boxes (particularly the
if tkinter.messagebox.askyesno():
thingy) just rapidly answer themselves with the 'no' option, rather than waiting for user input. Sometimes, the windows close off completely and cause the whole program to quit. However, although these errors are all the same (i.e. tkinter windows closing/answering themselves/stopping the program before they should), they usually happen in different places every time. I'm not sure if that's to do with the fact that tkinter is nested, opened, re-opened and closed numerous times within other code, which is making it run messily, but I have only destroyed tkinter windows in the right places, as far as I know.
Part of my code involves a while loop - I'm not sure if that could be interfering with the mainloop()s, but I couldn't find another way to allow the user to repeat the game as many times as they want.
I know this question is vague, but I'm mainly looking for tips - if it would be easier to diagnose if I split it up into different sections and tidy it up a bit, found an alternative for the while loop, etc.
Thanks!
TKinter dialogs should be fully completed and the results stored before moving onto the next section of code.
Make sure you provide all the arguments to the dialog (your example doesn't include the parameters).
result = tkinter.messagebox.askyesno('Confirm', 'Do you want to do this')
if result == true:
So I'm trying to complete my first projects, nothing special but having few problems.
1. When I run the code, the diode is constantly on, but it should go off. When I close the program I get error for this line
time.sleep(random.uniform(2,5))
Seems like it doesn't like being in the while loop.
2. While the diode is still on, if either of the players presses its button, it should get -2 points in penalty. But since I added the penalty, every time either of the players press it's button, they always get -2 points.
I think I might be related to the time.sleep bug.
For your convenience I put the code on Pastebin because it looks really bad and quite hard to read.
Link to code # Pastebin
It might help to have the whole error for the time.sleep line
But aside from any errors, your LED is always on because you only have one sleep, the IF statements are "instantaneous". The code basically boils down to this:
while True:
GPIO.output(led, 1)
time.sleep(random.uniform(2,5))
GPIO.output(led, 0)
Which is basically the same as this:
while True:
time.sleep(random.uniform(2,5))
GPIO.output(led, 0)
GPIO.output(led, 1)
Hope this helps!
Edit: I realized I didn't answer question 2. I have a suspicion it's related to whether or not board is "listening" while it's sleeping, but I don't have any experience with this. Based on https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/ maybe you need to use GPIO.event_detected for example...