如何将请求结果的响应插入到 tkinter python 上的列表框中?
how do I insert the response from requests results into the listbox on tkinter python?
我的代码有问题,如何将请求结果的响应插入或输入到列表框中,结果能否放在列表框的中间,我是 tkinter 的新手,这是代码:
from tkinter import *
from tkinter import messagebox
import requests
root = Tk()
root.configure(bg="black")
root.geometry('500x450')
root.resizable(0,0)
root.title("Cek Url")
c1 = "#00ee00"
c2 = "#222222"
c3 = "#111111"
root.tk_setPalette(background=c2,foreground=c1,activeBackground=c3,activeForeground=c2,highlightColor=c1,highlightBackground=c1)
Label(root,text = 'CHECK URL',bg="black", fg ="cyan", font ='aerial 20 bold').place(x=180, y=35)
link = StringVar()
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 100)
def ms():
messagebox.showinfo("About","Simple URL Check")
def main():
request = "https://unshorten.me/raw/" + link.get()
response = requests.get(request).text
print(response)
frame = Frame(root)
frame.place(width="370", height="215",x="60", y="133")
listbox = Listbox(frame, width="59",height="6")
scrollbar = Scrollbar(frame)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
Button(root,text = 'Check Url', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=main).place(x=203 ,y = 375)
Button(root,text = 'About', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=ms).place(x=25 ,y = 375)
root.mainloop()
您忘记将列表框放入框架中。
插入后会显示文字。
那你就可以用评论者说的listbox.insert('end', response)
了。
您还可以使该功能删除最后一个回复。
你可以找到很多你想知道的关于列表框的信息here。
由您决定如何格式化 text/output。 :)
from tkinter import *
from tkinter import messagebox
import requests
root = Tk()
root.configure(bg="black")
root.geometry('500x450')
root.resizable(0,0)
root.title("Cek Url")
c1 = "#00ee00"
c2 = "#222222"
c3 = "#111111"
root.tk_setPalette(background=c2,foreground=c1,activeBackground=c3,activeForeground=c2,highlightColor=c1,highlightBackground=c1)
Label(root,text = 'CHECK URL',bg="black", fg ="cyan", font ='aerial 20 bold').place(x=180, y=35)
link = StringVar()
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 100)
def ms():
messagebox.showinfo("About","Simple URL Check")
def main():
request = "https://unshorten.me/raw/" + link.get()
response = requests.get(request).text
listbox.insert(END, response) #Changed!
print(response)
frame = Frame(root)
frame.place(width="370", height="215",x="60", y="133")
listbox = Listbox(frame, width="59",height="6")
listbox.pack() #Changed!
scrollbar = Scrollbar(frame)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
Button(root,text = 'Check Url', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=main).place(x=203 ,y = 375)
Button(root,text = 'About', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=ms).place(x=25 ,y = 375)
root.mainloop()
我的代码有问题,如何将请求结果的响应插入或输入到列表框中,结果能否放在列表框的中间,我是 tkinter 的新手,这是代码:
from tkinter import *
from tkinter import messagebox
import requests
root = Tk()
root.configure(bg="black")
root.geometry('500x450')
root.resizable(0,0)
root.title("Cek Url")
c1 = "#00ee00"
c2 = "#222222"
c3 = "#111111"
root.tk_setPalette(background=c2,foreground=c1,activeBackground=c3,activeForeground=c2,highlightColor=c1,highlightBackground=c1)
Label(root,text = 'CHECK URL',bg="black", fg ="cyan", font ='aerial 20 bold').place(x=180, y=35)
link = StringVar()
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 100)
def ms():
messagebox.showinfo("About","Simple URL Check")
def main():
request = "https://unshorten.me/raw/" + link.get()
response = requests.get(request).text
print(response)
frame = Frame(root)
frame.place(width="370", height="215",x="60", y="133")
listbox = Listbox(frame, width="59",height="6")
scrollbar = Scrollbar(frame)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
Button(root,text = 'Check Url', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=main).place(x=203 ,y = 375)
Button(root,text = 'About', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=ms).place(x=25 ,y = 375)
root.mainloop()
您忘记将列表框放入框架中。 插入后会显示文字。
那你就可以用评论者说的listbox.insert('end', response)
了。
您还可以使该功能删除最后一个回复。
你可以找到很多你想知道的关于列表框的信息here。
由您决定如何格式化 text/output。 :)
from tkinter import *
from tkinter import messagebox
import requests
root = Tk()
root.configure(bg="black")
root.geometry('500x450')
root.resizable(0,0)
root.title("Cek Url")
c1 = "#00ee00"
c2 = "#222222"
c3 = "#111111"
root.tk_setPalette(background=c2,foreground=c1,activeBackground=c3,activeForeground=c2,highlightColor=c1,highlightBackground=c1)
Label(root,text = 'CHECK URL',bg="black", fg ="cyan", font ='aerial 20 bold').place(x=180, y=35)
link = StringVar()
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 100)
def ms():
messagebox.showinfo("About","Simple URL Check")
def main():
request = "https://unshorten.me/raw/" + link.get()
response = requests.get(request).text
listbox.insert(END, response) #Changed!
print(response)
frame = Frame(root)
frame.place(width="370", height="215",x="60", y="133")
listbox = Listbox(frame, width="59",height="6")
listbox.pack() #Changed!
scrollbar = Scrollbar(frame)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
Button(root,text = 'Check Url', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=main).place(x=203 ,y = 375)
Button(root,text = 'About', font = 'aerial 15 bold' ,bg = 'cyan', padx = 2, fg="black", command=ms).place(x=25 ,y = 375)
root.mainloop()