A quick reference for tkinter:
window = Tk()to set up the window.
widget = Widget(master=window)to set up a widget in the window.
widget.pack()to add the widget to the window. Note there is no way to temporarily hide a widget without removing it; instead,call
widget.configure()to update widget text content and other config properties. Like:
button.bind("<Button-1>", callback)to bind an on-click callback to a button. The callback takes the
tk.Eventas a parameter.
- Text edit fields (
textbox.insert(tk.END, s)to append
sto the textbox, and
textbox.delete("1.0", tk.END)to clear. Note that neither method will work if
textbox.state == "disabled".
textbox.configure(text=s)might get around this if you want to set the content to
window.mainloop()to start the app.
Worth noting that the
bind() callback is called synchronously. This means if you're, say, making a long-running HTTP request, you'll want to use
grequests to make the request asynchronously. I haven't needed that yet, though. Maybe next time I need to put
tk and HTTP together it will matter whether I halt the whole app dead. This time it didn't (disposable dev tool).
Much more detail at Real Python, which I used to get through the app in the first place. :)