I want to show the error message box pop up if anything goes wrong in the input. For example, in this code, if a number is entered, it will work. But if anything else is entered, the error will occur. In this example, we could specify that if the input is not a number, we show an error message box. But in other codes, there may be a lot of variables. Can we just take the whole code and show the error message box if an error occurs in any part of the code?
import tkinter as tk
from tkinter import *
window = tk.Tk()
canvas = tk.Canvas(window,width=980, height=580, highlightthickness=0)
canvas.pack()
def open_window(pll):
global g
g = pll*pll
show_button = tk.Button(canvas, text='Show square of number', command=lambda:show_result())
canvas.create_window(185, 30, window=show_button, anchor=tk.NW)
def show_result():
gg=str(g)
l1 = tk.Label(canvas, text=gg)
canvas.create_window(200,60, window=l1, anchor=tk.NW)
l0 = tk.Label(canvas, text="Enter Number")
canvas.create_window(3,5, window=l0, anchor=tk.NW)
PLz = tk.DoubleVar()
entry_PLz = tk.Entry(canvas, textvariable=PLz)
entry_PLz.config({"background": "gainsboro"})
canvas.create_window(250,15, window=entry_PLz)
submit_button = tk.Button(canvas, text="Process", command=lambda: open_window(PLz.get()))
canvas.create_window(100, 30, window=submit_button, anchor=tk.NW)
window.title('Try')
window.mainloop()