#๐ Tkinter button widget not changing state
14 messages ยท Page 1 of 1 (latest)
@cunning patrol
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
"""py
def parsepdf():
submit_button['state'] = 'disabled'
do the parsing
export to excel
root = tk.Tk()
submit_button = ttk.Button( root, text="Submit", command=parsepdf, )
root.mainloop()
"""
can you share your full code using a paste link?
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
I can't its too long and it'll take time to anonmise much of it. Either way, based on my googling I'd like to know how can I do real-time logging on a text widget in a tkinter window while a single function is running?
I don't get it. You told Tkinter to disable the button. Did you tell it to reenable the button afterwards?
if it all updates after the pdf parsing function is done, then you need a different way to update the UI during that process
any call to root.update_idletasks() will update the UI with whatever new information it has to display
but that would require multiple calls and updates from pdf parsing function
Is ParsePdf() running in a separate thread?
Presumably your parse pdf functionality takes a bit of time, and you want to give some indicator to the user to wait. Maybe you don't want your gui to hang while it process. That's fine that you want to disable the button for that duration, but the problem is when you mix synchronous and asynchronous code. Tkinter expects synchronous code so it'll freeze when executing a long function.
Instead the solution is to treat the gui as a shell that launches asynchronous functions. That is to say, it should dispatch and recieve messages.
Have some Tkinter state for the processing state of the parse function. Like Fashoomp suggested, have a separate asynchronus the updates that Tkinter state periodically.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.