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()









share|improve this question









New contributor




John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    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()









    share|improve this question









    New contributor




    John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      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()









      share|improve this question









      New contributor




      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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






      share|improve this question









      New contributor




      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 days ago









      200_success

      127k15148410




      127k15148410






      New contributor




      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      John Wilver

      112




      112




      New contributor




      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      John Wilver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          John Wilver is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          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





































          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.










           

          draft saved


          draft discarded


















          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.















           


          draft saved


          draft discarded














          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




















































































          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар