So I'm trying to automate my Manga reading and I'm coming into the trouble of finding out how to set a duration for each event. For example if I want it to scroll for 200 seconds then click the next page at X & Y coordinates, how would I go about doing this?
Note: I understand how to make pyautogui click. I'm more concerned on figuring out how to make it time delay.
import pyautogui
speed = input('how fast should it scroll')
sleepTime = input('how long before next scroll')
pyautogui.time.sleep(3)
while 0 < 10:
pyautogui.moveTo(918, 492, duration=26, tween=pyautogui.easeInOutQuad)
pyautogui.scroll(int(speed))
pyautogui.time.sleep(int(sleepTime))
pyautogui.FAILSAFE = True
Taken from the PyAutoGUI docs
Instead of:
pyautogui.time.sleep(3)
Do this:
pyautogui.PAUSE = 3
my question is actually quite easy but I get stuck with this issue.
I want to set timer to 2 second and then check if the mouse is still in the same poit as previous.
example: I detect the point of the mouse as (250, 500) and then put timer to 2 secs and check again where is the pointer now.
would appreciate your help :)
you can use time.sleep in cycle for
import time
for i in range(0,2):# range: 0,1 = 2 iteration = 2 sec
time.sleep(1)
I'd like to program a graphical clock, which has three pointers, one for the hour, another for the minute and the last for the second. The time is synced with my local PC time, so I need the clock pointers infinitely move like a real clock, unless I end the program. How can I determine the moving clock pointers? Is there a function for that? I looked it up in Turtle's documentation, but found none. Maybe I've missed something. Here's my yet incomplete code:
import time
import os
import cursor
import turtle
cursor.show()
s = turtle.Turtle()
turtle.bgcolor('Black')
hour = int(time.strftime('%H'))
minute = int(time.strftime('%M'))
second = int(time.strftime('%S'))
s.pensize(5)
s.pencolor('Red')
s.circle(200)
s.penup()
s.goto(0,200)
s.pendown()
s.left(90)
s.forward(100) #how can I make this rotate 30 degrees???
turtle.done()
Thank you in advance :))
I want to play music and get its position in seconds or minutes of when the music is playing. I used the pygame.mixer.music.get_pos() but the code is not working.
def f5secforward():
print(pygame.mixer.music.get_pos())
pygame.mixer.music.play(0,pygame.mixer.music.get_pos()//1000+5)
print(pygame.mixer.music.get_pos())
the first 'get_pos' works but after I change the current position of the song with pygame.mixer.music.play(loop,time) it assigns the value of the get_pos to 0
I have searched more and I just found out that get_pos() is not taking where the music is playing it just get the time that the Python mixer is busy.
Is there any solutions?
If you store the first get_pos as an integer (say "oldsongtime") then add the time the second get_pos produces (in your function it will be close to 0) and the time you're adding on (5000) you should get about the right time.
I say about because when I tried to make my own fast forward function the track sometimes jumped much further forward than it should have. Might be something to do with my pre_init not using the default frequency (on all the PCs I've used 44,100 Hz is too slow).
def f5secforward():
oldsongtime = pygame.mixer.music.get_pos()
change = 5000
print(oldsongtime)
pygame.mixer.music.play(0, (oldsongtime+change)/5000)
addedtime = pygame.mixer.music.get_pos()
print(addedtime)
currenttime = oldsongtime+change+addedtime
return currenttime
I am currently remaking flappy bird in Tkinter. (I understand this is bad, I explain why at the bottom.) My issue is with the pipes, and the speeds they scroll at and the distance they are from each other. Unless something is wrong with my logic, if a start the two pipes separated from each other then move them when they get to a certain point, and place them at the same point, they should retain the gap between them. This may be better explained in code.
from tkinter import *
import random
root = Tk()
root.geometry('430x640')
root.configure(background='turquoise')
canvas = Canvas(root,width=int(435),height=int(645))
canvas.configure(background='turquoise')
canvas.pack()
x, x2 = 400, 700
y = random.randint(0,300)
y2 = random.randint(0,300)
def drawPipe():
global x,x2,y,y2
canvas.coords(pipeTop,(x,0,(x+50),y))
canvas.coords(pipeBottom,(x,640,(x+50),(y+150)))
canvas.coords(pipeTop2,(x2,0,(x2+50),y2))
canvas.coords(pipeBottom2,(x2,640,(x2+50),(y2+150)))
x -= 3
x2 -= 3
if x < -46:
x = 435
y = random.randint(5,540)
if x2 <-46:
x2 = 435
y2 = random.randint(5,540)
root.after(1,drawPipe)
pipeTop = canvas.create_rectangle(x,0,(x+50),y,fill='green')
pipeBottom = canvas.create_rectangle(x,640,x+50,y+150,fill='green')
pipeTop2 = canvas.create_rectangle(x2,0,(x2+50),y,fill='green')
pipeBottom2 = canvas.create_rectangle(x2,640,(x2+50),(y2+150),fill='green')
drawPipe()
root.mainloop()
This is not my full code, but it is the bit concerned with drawing and updating the pipes. When run, this code will show you how the pipes scrolling speed up and down. I do not understand how this is possible. All the values for the pipes are the same apart from the starting positions. Is this due to the inefficient way Tkinter uses the after method? I attempted to use threading but this produced problems when using root.bind (see my previous question). Or is it due to a logic error? Thank you in advance to anyone who can help me.
Side note: I realise I should not be making a game in tkinter, especially one that requires multiple things to be happening at once. However, I am doing this at school and the modules I would like to use (Pygame or Pyglet) cannot be downloaded just for me to make a game that has no real purpose. If I could use something other than tkinter I probably would. Thank you for your help.
Using after(1,..) you get 1000FPS (Frames Per Second) but you don't need it - use after(20, ...) to get 50 FPS.
Beside using after(1,..) your program have no time to do other things - it have no time to execute all after() so you can get different speed.
With after(1,..) I couldn't even move window.
And my CPU became hotter so fan started working faster and louder.