How to do it...

The mouse pointer icon can be changed using the cursor option. In our example, we used the watch value to display the native busy cursor and question_arrow to display the regular arrow with a question mark:

import tkinter as tk

class App(tk.Tk):
def __init__(self):
super().__init__()
self.title("Cursors demo")
self.resizable(0, 0)
self.label = tk.Label(self, text="Click the button to start")
self.btn_launch = tk.Button(self, text="Start!",
command=self.perform_action)
self.btn_help = tk.Button(self, text="Help",
cursor="question_arrow")

btn_opts = {"side": tk.LEFT, "expand":True, "fill": tk.X,
"ipadx": 30, "padx": 20, "pady": 5}
self.label.pack(pady=10)
self.btn_launch.pack(**btn_opts)
self.btn_help.pack(**btn_opts)

def perform_action(self):
self.config(cursor="watch")
self.btn_launch.config(state=tk.DISABLED)
self.btn_help.config(state=tk.DISABLED)
self.label.config(text="Working...")
self.after(3000, self.end_action)

def end_action(self):
self.config(cursor="arrow")
self.btn_launch.config(state=tk.NORMAL)
self.btn_help.config(state=tk.NORMAL)
self.label.config(text="Done!")

if __name__ == "__main__":
app = App()
app.mainloop()

You can check out a complete list of valid cursor values and the system-specific ones in the official Tcl/Tk documentation at https://www.tcl.tk/man/tcl/TkCmd/cursors.htm.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset