Custom autoclick Python script
up vote
2
down vote
favorite
I'm a newbie Python programmer and I just made my first script which allows autoclicking into various positions of the screen (3 for now) an X number of times with an Y interval.
I'd like to know what do you think about my code, specifically if there is a more efficient way to do the same task.
No need to extend functionalities and such. I'm just curious to hear what more experienced developers think.
#import libraries
import pyautogui
from tkinter import *
import time
import subprocess
#settings
pyautogui.PAUSE = 1
pyautogui.FAILSAFE = True
pyautogui.size()
width, height = pyautogui.size()
initialStr = "Screen Size: " + str(width) +" - " +str(height)
print(initialStr)
x,y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr)
# displays screen size
def function():
print(initialStr)
#saves mouse position 1
def position():
time.sleep(2)
global xmouse, ymouse
xmouse, ymouse = pyautogui.position()
print(str(xmouse)+","+str(ymouse))
w2 = Label(ro, text="Position 1 set: "+str(xmouse)+","+str(ymouse)).grid(row=2,columnspan=2)
#saves mouse position 2
def position2():
time.sleep(2)
global xmouse2, ymouse2
xmouse2, ymouse2 = pyautogui.position()
print(str(xmouse2)+","+str(ymouse2))
w3 = Label(ro, text="Position 2 set: "+str(xmouse2)+","+str(ymouse2)).grid(row=4,columnspan=2)
#saves mouse position 3
def position3():
time.sleep(2)
global xmouse3, ymouse3
xmouse3, ymouse3 = pyautogui.position()
print(str(xmouse3)+","+str(ymouse3))
w4 = Label(ro, text="Position 3 set: "+str(xmouse3)+","+str(ymouse3)).grid(row=6,columnspan=2)
#saves number of cycles
def sel():
selection = "Value = " + str(iterations.get())
label = Label(ro, text="Number of cycles: "+str(iterations.get())).grid(row=11,columnspan=2)
#saves execution interval
def sel2():
selection = "Value = " + str(parametro_timer.get())
label2 = Label(ro, text="Execution interval set at: "+str(parametro_timer.get())+" seconds").grid(row=14,columnspan=2)
#starts autoclicking
def gogo():
#checks for unset variables, if one or more are unset it returns an error
try:
xmouse,xmouse2,xmouse3
except NameError:
label_error = Label(ro, foreground="red", text="ERROR: Some parameters are not set").grid(row=16,columnspan=2)
#if all settings have been set then the program can start autoclicking
else:
time.sleep(2)
timer=int(parametro_timer.get())
parametro_range=int(iterations.get())
for i in range(0,parametro_range):
pyautogui.click(xmouse, ymouse)
time.sleep(timer)
pyautogui.click(xmouse2, ymouse2)
time.sleep(timer)
pyautogui.click(xmouse3, ymouse3)
time.sleep(timer)
#GUI
ro = Tk()
ro.wm_title("AutoClicker1.0")
#scale variables
iterations = DoubleVar()
parametro_timer = DoubleVar()
w1 = Label(ro, text=initialStr).grid(row=0,columnspan=2, pady=15)
w2 = Label(ro, text="Position 1 is unset").grid(row=2,columnspan=2)
w3 = Label(ro, text="Position 2 is unset").grid(row=4,columnspan=2)
w4 = Label(ro, text="Position 3 is unset").grid(row=6,columnspan=2)
button = Button(ro, text="Set Position 1 [2 seconds to hover into position]", command=position).grid(row=1,columnspan=2)
button = Button(ro, text="Set Position 2 [2 seconds to hover into position]", command=position2).grid(row=3,columnspan=2)
button = Button(ro, text="Set Position 3 [2 seconds to hover into position]", command=position3).grid(row=5,columnspan=2)
scale = Scale( ro, variable = iterations, orient=HORIZONTAL, from_=5, to=100 ).grid(row=9,columnspan=2)
button = Button(ro, text="Set number of cycles", command=sel).grid(row=10,columnspan=2)
label = Label(ro, text="Cycles are unset (Default=5)").grid(row=11,columnspan=2)
scale1 = Scale( ro, variable = parametro_timer, orient=HORIZONTAL, from_=2, to=15 ).grid(row=12,columnspan=2)
button = Button(ro, text="Set execution interval", command=sel2).grid(row=13,columnspan=2)
label2 = Label(ro, text="Execution interval is unset (Default=2)").grid(row=14,columnspan=2)
button = Button(ro, text="Start", command=gogo).grid(row=15,columnspan=2,padx=110,pady=5)
label_error = Label(ro, text="").grid(row=16,columnspan=2)
ro.mainloop()
python beginner python-3.x tkinter
New contributor
add a comment |
up vote
2
down vote
favorite
I'm a newbie Python programmer and I just made my first script which allows autoclicking into various positions of the screen (3 for now) an X number of times with an Y interval.
I'd like to know what do you think about my code, specifically if there is a more efficient way to do the same task.
No need to extend functionalities and such. I'm just curious to hear what more experienced developers think.
#import libraries
import pyautogui
from tkinter import *
import time
import subprocess
#settings
pyautogui.PAUSE = 1
pyautogui.FAILSAFE = True
pyautogui.size()
width, height = pyautogui.size()
initialStr = "Screen Size: " + str(width) +" - " +str(height)
print(initialStr)
x,y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr)
# displays screen size
def function():
print(initialStr)
#saves mouse position 1
def position():
time.sleep(2)
global xmouse, ymouse
xmouse, ymouse = pyautogui.position()
print(str(xmouse)+","+str(ymouse))
w2 = Label(ro, text="Position 1 set: "+str(xmouse)+","+str(ymouse)).grid(row=2,columnspan=2)
#saves mouse position 2
def position2():
time.sleep(2)
global xmouse2, ymouse2
xmouse2, ymouse2 = pyautogui.position()
print(str(xmouse2)+","+str(ymouse2))
w3 = Label(ro, text="Position 2 set: "+str(xmouse2)+","+str(ymouse2)).grid(row=4,columnspan=2)
#saves mouse position 3
def position3():
time.sleep(2)
global xmouse3, ymouse3
xmouse3, ymouse3 = pyautogui.position()
print(str(xmouse3)+","+str(ymouse3))
w4 = Label(ro, text="Position 3 set: "+str(xmouse3)+","+str(ymouse3)).grid(row=6,columnspan=2)
#saves number of cycles
def sel():
selection = "Value = " + str(iterations.get())
label = Label(ro, text="Number of cycles: "+str(iterations.get())).grid(row=11,columnspan=2)
#saves execution interval
def sel2():
selection = "Value = " + str(parametro_timer.get())
label2 = Label(ro, text="Execution interval set at: "+str(parametro_timer.get())+" seconds").grid(row=14,columnspan=2)
#starts autoclicking
def gogo():
#checks for unset variables, if one or more are unset it returns an error
try:
xmouse,xmouse2,xmouse3
except NameError:
label_error = Label(ro, foreground="red", text="ERROR: Some parameters are not set").grid(row=16,columnspan=2)
#if all settings have been set then the program can start autoclicking
else:
time.sleep(2)
timer=int(parametro_timer.get())
parametro_range=int(iterations.get())
for i in range(0,parametro_range):
pyautogui.click(xmouse, ymouse)
time.sleep(timer)
pyautogui.click(xmouse2, ymouse2)
time.sleep(timer)
pyautogui.click(xmouse3, ymouse3)
time.sleep(timer)
#GUI
ro = Tk()
ro.wm_title("AutoClicker1.0")
#scale variables
iterations = DoubleVar()
parametro_timer = DoubleVar()
w1 = Label(ro, text=initialStr).grid(row=0,columnspan=2, pady=15)
w2 = Label(ro, text="Position 1 is unset").grid(row=2,columnspan=2)
w3 = Label(ro, text="Position 2 is unset").grid(row=4,columnspan=2)
w4 = Label(ro, text="Position 3 is unset").grid(row=6,columnspan=2)
button = Button(ro, text="Set Position 1 [2 seconds to hover into position]", command=position).grid(row=1,columnspan=2)
button = Button(ro, text="Set Position 2 [2 seconds to hover into position]", command=position2).grid(row=3,columnspan=2)
button = Button(ro, text="Set Position 3 [2 seconds to hover into position]", command=position3).grid(row=5,columnspan=2)
scale = Scale( ro, variable = iterations, orient=HORIZONTAL, from_=5, to=100 ).grid(row=9,columnspan=2)
button = Button(ro, text="Set number of cycles", command=sel).grid(row=10,columnspan=2)
label = Label(ro, text="Cycles are unset (Default=5)").grid(row=11,columnspan=2)
scale1 = Scale( ro, variable = parametro_timer, orient=HORIZONTAL, from_=2, to=15 ).grid(row=12,columnspan=2)
button = Button(ro, text="Set execution interval", command=sel2).grid(row=13,columnspan=2)
label2 = Label(ro, text="Execution interval is unset (Default=2)").grid(row=14,columnspan=2)
button = Button(ro, text="Start", command=gogo).grid(row=15,columnspan=2,padx=110,pady=5)
label_error = Label(ro, text="").grid(row=16,columnspan=2)
ro.mainloop()
python beginner python-3.x tkinter
New contributor
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm a newbie Python programmer and I just made my first script which allows autoclicking into various positions of the screen (3 for now) an X number of times with an Y interval.
I'd like to know what do you think about my code, specifically if there is a more efficient way to do the same task.
No need to extend functionalities and such. I'm just curious to hear what more experienced developers think.
#import libraries
import pyautogui
from tkinter import *
import time
import subprocess
#settings
pyautogui.PAUSE = 1
pyautogui.FAILSAFE = True
pyautogui.size()
width, height = pyautogui.size()
initialStr = "Screen Size: " + str(width) +" - " +str(height)
print(initialStr)
x,y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr)
# displays screen size
def function():
print(initialStr)
#saves mouse position 1
def position():
time.sleep(2)
global xmouse, ymouse
xmouse, ymouse = pyautogui.position()
print(str(xmouse)+","+str(ymouse))
w2 = Label(ro, text="Position 1 set: "+str(xmouse)+","+str(ymouse)).grid(row=2,columnspan=2)
#saves mouse position 2
def position2():
time.sleep(2)
global xmouse2, ymouse2
xmouse2, ymouse2 = pyautogui.position()
print(str(xmouse2)+","+str(ymouse2))
w3 = Label(ro, text="Position 2 set: "+str(xmouse2)+","+str(ymouse2)).grid(row=4,columnspan=2)
#saves mouse position 3
def position3():
time.sleep(2)
global xmouse3, ymouse3
xmouse3, ymouse3 = pyautogui.position()
print(str(xmouse3)+","+str(ymouse3))
w4 = Label(ro, text="Position 3 set: "+str(xmouse3)+","+str(ymouse3)).grid(row=6,columnspan=2)
#saves number of cycles
def sel():
selection = "Value = " + str(iterations.get())
label = Label(ro, text="Number of cycles: "+str(iterations.get())).grid(row=11,columnspan=2)
#saves execution interval
def sel2():
selection = "Value = " + str(parametro_timer.get())
label2 = Label(ro, text="Execution interval set at: "+str(parametro_timer.get())+" seconds").grid(row=14,columnspan=2)
#starts autoclicking
def gogo():
#checks for unset variables, if one or more are unset it returns an error
try:
xmouse,xmouse2,xmouse3
except NameError:
label_error = Label(ro, foreground="red", text="ERROR: Some parameters are not set").grid(row=16,columnspan=2)
#if all settings have been set then the program can start autoclicking
else:
time.sleep(2)
timer=int(parametro_timer.get())
parametro_range=int(iterations.get())
for i in range(0,parametro_range):
pyautogui.click(xmouse, ymouse)
time.sleep(timer)
pyautogui.click(xmouse2, ymouse2)
time.sleep(timer)
pyautogui.click(xmouse3, ymouse3)
time.sleep(timer)
#GUI
ro = Tk()
ro.wm_title("AutoClicker1.0")
#scale variables
iterations = DoubleVar()
parametro_timer = DoubleVar()
w1 = Label(ro, text=initialStr).grid(row=0,columnspan=2, pady=15)
w2 = Label(ro, text="Position 1 is unset").grid(row=2,columnspan=2)
w3 = Label(ro, text="Position 2 is unset").grid(row=4,columnspan=2)
w4 = Label(ro, text="Position 3 is unset").grid(row=6,columnspan=2)
button = Button(ro, text="Set Position 1 [2 seconds to hover into position]", command=position).grid(row=1,columnspan=2)
button = Button(ro, text="Set Position 2 [2 seconds to hover into position]", command=position2).grid(row=3,columnspan=2)
button = Button(ro, text="Set Position 3 [2 seconds to hover into position]", command=position3).grid(row=5,columnspan=2)
scale = Scale( ro, variable = iterations, orient=HORIZONTAL, from_=5, to=100 ).grid(row=9,columnspan=2)
button = Button(ro, text="Set number of cycles", command=sel).grid(row=10,columnspan=2)
label = Label(ro, text="Cycles are unset (Default=5)").grid(row=11,columnspan=2)
scale1 = Scale( ro, variable = parametro_timer, orient=HORIZONTAL, from_=2, to=15 ).grid(row=12,columnspan=2)
button = Button(ro, text="Set execution interval", command=sel2).grid(row=13,columnspan=2)
label2 = Label(ro, text="Execution interval is unset (Default=2)").grid(row=14,columnspan=2)
button = Button(ro, text="Start", command=gogo).grid(row=15,columnspan=2,padx=110,pady=5)
label_error = Label(ro, text="").grid(row=16,columnspan=2)
ro.mainloop()
python beginner python-3.x tkinter
New contributor
I'm a newbie Python programmer and I just made my first script which allows autoclicking into various positions of the screen (3 for now) an X number of times with an Y interval.
I'd like to know what do you think about my code, specifically if there is a more efficient way to do the same task.
No need to extend functionalities and such. I'm just curious to hear what more experienced developers think.
#import libraries
import pyautogui
from tkinter import *
import time
import subprocess
#settings
pyautogui.PAUSE = 1
pyautogui.FAILSAFE = True
pyautogui.size()
width, height = pyautogui.size()
initialStr = "Screen Size: " + str(width) +" - " +str(height)
print(initialStr)
x,y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr)
# displays screen size
def function():
print(initialStr)
#saves mouse position 1
def position():
time.sleep(2)
global xmouse, ymouse
xmouse, ymouse = pyautogui.position()
print(str(xmouse)+","+str(ymouse))
w2 = Label(ro, text="Position 1 set: "+str(xmouse)+","+str(ymouse)).grid(row=2,columnspan=2)
#saves mouse position 2
def position2():
time.sleep(2)
global xmouse2, ymouse2
xmouse2, ymouse2 = pyautogui.position()
print(str(xmouse2)+","+str(ymouse2))
w3 = Label(ro, text="Position 2 set: "+str(xmouse2)+","+str(ymouse2)).grid(row=4,columnspan=2)
#saves mouse position 3
def position3():
time.sleep(2)
global xmouse3, ymouse3
xmouse3, ymouse3 = pyautogui.position()
print(str(xmouse3)+","+str(ymouse3))
w4 = Label(ro, text="Position 3 set: "+str(xmouse3)+","+str(ymouse3)).grid(row=6,columnspan=2)
#saves number of cycles
def sel():
selection = "Value = " + str(iterations.get())
label = Label(ro, text="Number of cycles: "+str(iterations.get())).grid(row=11,columnspan=2)
#saves execution interval
def sel2():
selection = "Value = " + str(parametro_timer.get())
label2 = Label(ro, text="Execution interval set at: "+str(parametro_timer.get())+" seconds").grid(row=14,columnspan=2)
#starts autoclicking
def gogo():
#checks for unset variables, if one or more are unset it returns an error
try:
xmouse,xmouse2,xmouse3
except NameError:
label_error = Label(ro, foreground="red", text="ERROR: Some parameters are not set").grid(row=16,columnspan=2)
#if all settings have been set then the program can start autoclicking
else:
time.sleep(2)
timer=int(parametro_timer.get())
parametro_range=int(iterations.get())
for i in range(0,parametro_range):
pyautogui.click(xmouse, ymouse)
time.sleep(timer)
pyautogui.click(xmouse2, ymouse2)
time.sleep(timer)
pyautogui.click(xmouse3, ymouse3)
time.sleep(timer)
#GUI
ro = Tk()
ro.wm_title("AutoClicker1.0")
#scale variables
iterations = DoubleVar()
parametro_timer = DoubleVar()
w1 = Label(ro, text=initialStr).grid(row=0,columnspan=2, pady=15)
w2 = Label(ro, text="Position 1 is unset").grid(row=2,columnspan=2)
w3 = Label(ro, text="Position 2 is unset").grid(row=4,columnspan=2)
w4 = Label(ro, text="Position 3 is unset").grid(row=6,columnspan=2)
button = Button(ro, text="Set Position 1 [2 seconds to hover into position]", command=position).grid(row=1,columnspan=2)
button = Button(ro, text="Set Position 2 [2 seconds to hover into position]", command=position2).grid(row=3,columnspan=2)
button = Button(ro, text="Set Position 3 [2 seconds to hover into position]", command=position3).grid(row=5,columnspan=2)
scale = Scale( ro, variable = iterations, orient=HORIZONTAL, from_=5, to=100 ).grid(row=9,columnspan=2)
button = Button(ro, text="Set number of cycles", command=sel).grid(row=10,columnspan=2)
label = Label(ro, text="Cycles are unset (Default=5)").grid(row=11,columnspan=2)
scale1 = Scale( ro, variable = parametro_timer, orient=HORIZONTAL, from_=2, to=15 ).grid(row=12,columnspan=2)
button = Button(ro, text="Set execution interval", command=sel2).grid(row=13,columnspan=2)
label2 = Label(ro, text="Execution interval is unset (Default=2)").grid(row=14,columnspan=2)
button = Button(ro, text="Start", command=gogo).grid(row=15,columnspan=2,padx=110,pady=5)
label_error = Label(ro, text="").grid(row=16,columnspan=2)
ro.mainloop()
python beginner python-3.x tkinter
python beginner python-3.x tkinter
New contributor
New contributor
edited 2 days ago
200_success
127k15148410
127k15148410
New contributor
asked 2 days ago
John Wilver
112
112
New contributor
New contributor
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
John Wilver is a new contributor. Be nice, and check out our Code of Conduct.
John Wilver is a new contributor. Be nice, and check out our Code of Conduct.
John Wilver is a new contributor. Be nice, and check out our Code of Conduct.
John Wilver is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207477%2fcustom-autoclick-python-script%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password