There is a function that generates a specified number of entries in equipment settings with partially random values. I decided to try to make a window familiar to the user using Tkinter, but they are zero before entering the values ​​of variables in the fields, although the function should work after entering the values

from tkinter import * import requests import time import random window = Tk() window.title("Add SVLAN Rx") window.geometry('300x300') lbl = Label(window, text="Количество svlan rx(1 - 64000):", font=("Arial Bold", 12)) lbl.grid(column=0, row=0) i1 = Entry(window) i1.grid(column=1, row=0) i1.focus() i1 = i1.get() lb2 = Label(window, text="Ip адрес модема:", font=("Arial Bold", 12)) lb2.grid(column=0, row=1) addr1 = Entry(window) addr1_entry = Entry(textvariable=addr1) addr1_entry.grid(column=1, row=1) addr1 = addr1_entry.get() def svlan(i1, addr1): i = 1 #addr = str(addr) while i != i1: i += 1 s = str(i) v = random.randint(2, 4095) v1 = str(v) response = requests.get('http://'+addr1+'/cx4?da=0&du=65534&dd=' + v1 + '&db=' + s + '&tc=&ta=Apply') time.sleep(0.05) btn = Button(window, text="Сгенерить!", command=svlan(i1, addr1)) btn.grid(column=1, row=2) window.mainloop() 

Mistake

 "C:\Program Files\Python35\python.exe" C:/Users/Anton/Desktop/python/express/button.py Traceback (most recent call last): File "C:/Users/Anton/Desktop/python/express/button.py", line 40, in <module> btn = Button(window, text="Сгенерить!", command=svlan(i1, addr1)) File "C:/Users/Anton/Desktop/python/express/button.py", line 36, in svlan response = requests.get('http://'+addr1+'/cx4?da=0&du=65534&dd=' + v1 + '&db=' + s + '&tc=&ta=Apply') File "C:\Program Files\Python35\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "C:\Program Files\Python35\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "C:\Program Files\Python35\lib\site-packages\requests\sessions.py", line 519, in request prep = self.prepare_request(req) File "C:\Program Files\Python35\lib\site-packages\requests\sessions.py", line 462, in prepare_request hooks=merge_hooks(request.hooks, self.hooks), File "C:\Program Files\Python35\lib\site-packages\requests\models.py", line 313, in prepare self.prepare_url(url, params) File "C:\Program Files\Python35\lib\site-packages\requests\models.py", line 390, in prepare_url raise InvalidURL("Invalid URL %r: No host supplied" % url) requests.exceptions.InvalidURL: Invalid URL 'http:///cx4?da=0&du=65534&dd=2775&db=2&tc=&ta=Apply': No host supplied Process finished with exit code 1 
  • Add lambda to Button Button(window, text="Сгенерить!", command=lambda: svlan(i1, addr1)) - Twiss
  • much better already, only from the addr1 field doesn’t accept requests.exceptions.InvalidURL: Invalid URL 'http: /// cx4? da = 0 & du = 65534 & dd = 2605 & db = 2 & tc = & ta = Apply': No host - Anton
  • Button(window, text="Сгенерить!", command=lambda: svlan(i1.get(), addr1.get())) - Twiss

0