I’m barely able to do python but 6 years ago, I managed to modify a bunch of programs to create an application as a museum volunteer. Now, I am trying to use one of these both as-is, and modified to be clickable (two versions). The clickable version gets an error that I just don’t understand (which is true most of the time these days because, at 78, I have trouble remembering anything I did.
The program takes a number of parameters and outputs a label based in those parameters and can send signal to parent or kill child programs. That all works. It has been in operation for 6 years at multiple museums in an application I wrote on a Raspberry Pi. Now I need it to have a clickable way to die but send signal or kill programs just like a similar working one that does the same with pictures.
I’ve spent hours searching the web and trying to make adaptions based on similar code without success. I know it’s some dumb mistake because python is still a mystery to me. I learned Fortran in engineering school and used it for years but that was a lifetime ago.
#
# Modified by JP
# Version="4/10/19a"
Version="Rev 2.0 9/19/25 JP"
#
# run command: python3 py3_Message.py [X offset] [Y offset] [character size] [ font ] [Char Color] [BG Color] [Print string]
#
# Python3
import tkinter as tk
import sys
from pathlib import Path
import PIL
import subprocess
from subprocess import Popen
# Get variables
#
MyName=sys.argv[0]
Xoffset=sys.argv[1]
Yoffset=sys.argv[2]
Char_size=sys.argv[3]
Font_name=sys.argv[4]
fg_color=sys.argv[5]
bg_color=sys.argv[6]
Process_Id=sys.argv[7]
MyString=sys.argv[8]
print (MyName,': ',Version)
def Label_clicked(event):
global Process_Id, MyName
print(MyName,': ','You clicked me')
#
# Check if Process_Id is positive or negative or zero
#
n_Process_Id=int(Process_Id)
if (n_Process_Id>0):
print (MyName,": Killing children of ",n_Process_Id)
p1=Popen (["/usr/bin/pkill",'-P',Process_Id], stderr=subprocess.STDOUT)
elif (n_Process_Id<0):
n_Process_Id=(0-n_Process_Id)
Process_Id=str(n_Process_Id)
print (MyName,": Sending signal to ",n_Process_Id)
p1=Popen (["/bin/kill",'-2',Process_Id], stderr=subprocess.STDOUT)
else:
exit(0)
#
master = tk.Tk()
# Remove titlebar
master.overrideredirect(1)
# label auto-adjusts X and Y sizes to the font
label_font = (Font_name, Char_size)
master.geometry('+%s+%s' % (Xoffset,Yoffset))
Label.bind("<Button-1>", Label_clicked)
Label(master, anchor='center', text=MyString, font=label_font, bg=bg_color,
fg=fg_color, relief='raised', bd=3).pack(fill='x', padx=0, pady=0)
master.mainloop()
This is the output message:
python3 ~/runtime/Programs.Source/py3_Message_Clickable.py ‘100’ ‘400’ “40” “Helvetica Bold” “Red” “White” 0 “OUTSIDE”
/home/admin/runtime/Programs.Source/py3_Message_Clickable.py : Rev 2.0 9/19/25 JP
Traceback (most recent call last):
File “/home/admin/runtime/Programs.Source/py3_Message_Clickable.py”, line 57, in
Label.bind(“”, Label_clicked)
^^^^^
NameError: name ‘Label’ is not defined