Im trying to make a application that takes in a url and in return returns that url back to be proccessed with tkinter. But I have tried everything and its not working. How would I do this I am trying to save the txtfld entry variable. I tried passing that variable through but it wouldnt work
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()
Thanks
CodePudding user response:
If I am understanding correctly, you want the text typed into the Entry box. All you should need is the get method.
url = txtfld.get()
So if you are going to bind some action to the entry box upon text being entered and the user clicking return, you would have something like:
def action():
url = txtfld.get()
# do something with url
txtfld.bind('<Return>', lambda _: action())
Or a button:
button = Button(window, text="Submit", command=action)
Once you have the url stored in a variable, you can use the answer on How to read html from a url... to get the html.