Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to save a Entry Widget Tkinter as a variable

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading