I am developing a program in which specific elements are to be extracted from live HTML pages, shown to the user in the GUI and then on the selection of the user, they are to be printed in an HTML document. I am able to perform most of these, need help with a small problem. In the code presented below, I have extracted one title from a website and have used Checkbox function to display this in the GUI, if the checkbox is ticked by the user, it should be printed in the HTML document. However, the value of the checkbox always remains "False" whether it is checked or unchecked and I am unable to proceed further with the code. Can you please highlight where the issue is? I implemented the save_function just to check the value of the Checkbox and it is always "False".
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.gui()
def game_function(self):
game = Tk()
game.geometry('600x400')
game.title('Upcoming Video Game Releases')
game.resizable(0,0)
if self.check.get() == 0:
self.check_g_1 = BooleanVar()
url = "https://www.metacritic.com/browse/games/release-date/coming-soon/all/date"
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
request = urllib.request.Request(url,headers={'User-Agent': user_agent})
response = urllib.request.urlopen(request)
encoding = response.info().get_param('charset', 'utf8')
html = response.read().decode(encoding)
date_title_1 = re.findall('<span>(.*?)</span>',html,re.DOTALL)[1]
title_1 = re.findall('<h3>(.*?)</h3>',html,re.DOTALL)[0]
title1_subtitle = Checkbutton(game, text = title_1.lstrip(), fg='black', font = ('Arial', 12), justify=LEFT, variable=self.check_g_1)
title1_subtitle.place(relx=0, rely=0)
date_1 = Label(game, text = date_title_1.lstrip(), fg='black', font = ('Arial', 12))
date_1.place(relx=0.6, rely=0)
else:
print("FFF")
save_button = Button(game, text = 'Save', font = ('Arial', 14), fg='black', bg='white', relief = 'solid', command=self.save_function)
save_button.place(relx=0.38, rely=0.72, height=60, width=200)
save_button.configure(wraplength='200')
def save_function(self):
print(self.check_g_1.get())
I am concerned with the value self.check_g_1
self.checkandself.check_g_1? There's isn't enough code in your question to answer it. Please create a minimal reproducible example that reproduces the issue.self.check_g_1because you're not following the PEP 8 - Style Guide for Python Code recommendations which makes it difficult to read the code (especially here on this site). Regardless, it's hardly "minimal"—all thaturllibandrestuff likely has nothing to do with the issue, and so only obscures the possibly important stuff.