我正在嘗試制作一個接受 url 的應用程式,然后回傳該 url 以使用 tkinter 進行處理。但我已經嘗試了一切,但它不起作用。我將如何執行此操作我正在嘗試保存 txtfld 條目變數。我嘗試通過該變數但它不起作用
from tkinter import *
from TikTokApi import TikTokApi
# This is generating the tt_webid_v2 cookie
api = TikTokApi.get_instance()
window=Tk()
window.iconbitmap("unnamed.ico")
img = PhotoImage(file="dw.png")
label = Label(
window,
image=img
)
label.place(x=0, y=0)
lbl=Label(window, text="Welcome to dillytok please enter the link of \n what you would like to download", fg='red', font=("Helvetica", 16))
lbl.place(x=40, y=50)
txtfld=Entry(window, text="This is Entry Widget", bd=1)
txtfld.place(x=100, y=120, width=300,height=20)
txtfld.get()
# This is generating the tt_webid_v2 cookie
# need to pass it to methods you want to download
device_id = api.generate_device_id()
tiktoks = api.get_tiktok_by_url(txtfld)
# Defining mp4 bytes
video_bytes = api.get_video_by_tiktok(tiktoks, custom_device_id=device_id)
def download():
with open("dillytok.mp4", "wb") as out:
out.write(video_bytes)
btn=Button(window, text="Download", fg='blue', command=download)
btn.place(x=210, y=170)
btn.pack()
window.title('dillytok')
window.geometry("500x300 30 30")
# need to pass it to methods you want to download
window.mainloop()
謝謝
uj5u.com熱心網友回復:
如果我理解正確,您希望將文本輸入到輸入框中。您所需要的只是 get 方法。
url = txtfld.get()
因此,如果您要在輸入文本并且用戶單擊回傳時將某些操作系結到輸入框,您將有如下內容:
def action():
url = txtfld.get()
# do something with url
txtfld.bind('<Return>', lambda _: action())
或者一個按鈕:
button = Button(window, text="Submit", command=action)
將 url 存盤在變數中后,您可以使用有關如何從 url 讀取 html...獲取 html的答案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/396320.html
上一篇:用X個變數計算
