how the "def" function should be redone to read the urls entered by the user from the interface, and check for availability with output
I tried to do it, but it didn't work, I don't understand how to do it right
import requests
import time
import tkinter
from tkinter import *
from tkinter import messagebox
from sys import argv
def SiteChek():
sylk = weight_tf.get()
for url in sylk:
response = requests.get(url)
if response.status_code != 200:
messagebox.showinfo(f"{url = }")
messagebox.showinfo(f"{response.status_code = }")
time.sleep(0.4)
window = Tk()
window.title("SiteChecker")
window.geometry('400x300')
frame = Frame(
window,
padx = 10,
pady = 10
)
frame.pack(expand=True)
weight_lb = Label(
frame,
text="Insert links "
)
weight_lb.grid(row=3, column=1)
weight_tf = Entry(
frame,
)
weight_tf.grid(row=3, column=3)
cal_btn = Button(
frame,
command = SiteChek,
text='Start checking',
)
cal_btn.grid(row=4, column=3)
window.mainloop()
CodePudding user response:
there is how to do it :
def SiteCheck():
Site_Value=GetSiteBox.get("1.0","end-1c")
Get_Response = requests.get(Site_Value)
if Get_Response != 200:
messagebox.showinfo(title = 'Will It Works ?', message = f"The website \"{Site_Value}\" works ! ")
else :
messagebox.showerror(title="OH NO !", message= f"The website \"{Site_Value}\" doesn't works ")
time.sleep(0.4)
GetSiteBox.get("1.0","end-1c")
retrieves all the text entered into the GetSiteBox
widget, from the beginning of the text to the end of the text, minus the last newline character. It uses the get()
method of the Text
widget, which takes two arguments for the starting and ending index of the text to retrieve.
As well as the messagebox
that i modified because u needed to write title=
and for the message part message=
.
As for this part :
MainFrame = Frame(
window,
padx = 10,
pady = 10
)
MainFrame.pack(expand=True)
weight_lb = Label(
MainFrame,
text="Insert links "
)
weight_lb.grid(row=3, column=1)
GetSiteBox = Text(
MainFrame,
height=1,
width= 20
)
GetSiteBox.grid(row=3, column=3)
Check_Button = Button(
MainFrame,
command = SiteCheck,
text='Start checking',
)
Check_Button.grid(row=4, column=3)
window.mainloop()
I just made GetSiteBox
a Text
Widget to make it easier and made some GUI modificiation because of the Text
Widget and I also changed the names of the variables so it will be more easy for you if you want to make a bigger project.
Sorry for poor explanation and bad english, I hope this helped !