0

This is a scuffed version of aimlabs I'm working on right now. and I know there is a way to make this more elegant. I need to put one function to multiple widgets for Python GUI.

def clicked1():
    clicker1.place(x=randint(1, 900), y=randint(1, 600))
def clicked2():
    clicker2.place(x=randint(1, 900), y=randint(1, 600))
def clicked3():
    clicker3.place(x=randint(1, 900), y=randint(1, 600))
def clicked4():
    clicker4.place(x=randint(1, 900), y=randint(1, 600))
def clicked5():
    clicker5.place(x=randint(1, 900), y=randint(1, 600))

clicker1 = Button(root, text='CLICK!', width=10, height=5, command=clicked1)
clicker1.place(x=randint(1, 900), y=randint(1, 600))
clicker2 = Button(root, text='CLICK!', width=10, height=5, command=clicked2)
clicker2.place(x=randint(1, 900), y=randint(1, 600))
clicker3 = Button(root, text='CLICK!', width=10, height=5, command=clicked3)
clicker3.place(x=randint(1, 900), y=randint(1, 600))
clicker4 = Button(root, text='CLICK!', width=10, height=5, command=clicked4)
clicker4.place(x=randint(1, 900), y=randint(1, 600))
clicker5 = Button(root, text='CLICK!', width=10, height=5, command=clicked5)
clicker5.place(x=randint(1, 900), y=randint(1, 600))
  • Are you just looking to learn how to [pass variables to a function](https://stackoverflow.com/questions/16043797/python-passing-variables-between-functions)? Or [this thread](https://stackoverflow.com/questions/39962564/passing-variables-between-functions-in-python)? – BruceWayne Sep 14 '21 at 16:29
  • I'm looking for a more elegant way of doing this code. Like using a loop or class. – rodiemertomi Sep 14 '21 at 23:09

0 Answers0