I’m writing my program in python and have it working properly, but it’s over 500 lines of code. I think there is a way I can condense my code, but I’m not sure how I should do it
Here’s an example of some of my code:
def click():
if clicked1.get() == "app1":
os.startfile(r"C:UsersredDesktopapp1")
i = 0
while i < 20:
try:
app.connect(title_re=".*app1")
break
except pywinauto.findwindows.ElementNotFoundError:
time.sleep(1)
i += 1
app1 = app.top_window()
app1.move_window(x1, y1)
time.sleep(.5)
app1.maximize()
if clicked1.get() == "app2":
os.startfile(r"C:Program Files (x86)app2")
i = 0
while i < 20:
try:
app.connect(title_re=".*app2")
break
except pywinauto.findwindows.ElementNotFoundError:
time.sleep(1)
i += 1
app1 = app.top_window()
app1.move_window(x1, y1)
time.sleep(.5)
app1.maximize()
I basically have about 20 of those if statements for each different
application and for each different clicked (1-4). Is there any way I can shrink my code so it doesn’t take up so many lines? Perhaps using variables?