![]() |
VOOZH | about |
The library, BeautifulSoup in Python apart from extracting data out of HTML or XML files, helps in searching, modifying, and navigating the parse tree. Are you not able to obtain the value from a widget after the button click? Donβt worry. Just read the article thoroughly to know the procedure of obtaining the value after button click with BeautifulSoup.
from bs4 import BeautifulSoup as bs
from tkinter import *
import os
base=os.path.dirname(os.path.abspath(β#Name of Python file in which you are currently working))
html=open(os.path.join(base, '#Name of HTML file from which you wish to read value'))
soup=bs(html, 'html.parser')
value=soup.find("#Name of widget", {"id":"#Id name of the widget"}).text
app=Tk()
app.title("#Title of the app")
app.geometry('#Geometry you wish to give to app')
def func():
with open('#Name of text file in which you wish to write value', "w", encoding='utf-8') as f_output:
f_output.write(value)
b1=Button(app, text='#Text you want to give to button', command=func)
b1.grid(padx=#Padding from x-axis, pady=#Padding from y-axis)
app.mainloop( )
Consider the following HTML source code.
Let us consider you want to obtain the value 'Mango' in the txt file 'text_file' after the button click 'Click here!', then you can write the following code.