Macro buttons for CoolTerm, using Python

If you have specific questions or problems with any of my Freeware applications, post them here.

Macro buttons for CoolTerm, using Python

Postby roger » Sat Jun 06, 2020 2:03 pm

With CoolTerm 1.7.0 supporting cross-platform scripting, it is now possible to create macro buttons that work on all supported operating systems, as demonstrated by the following script:

Code: Select all
# Creating Macro Buttons using tkinter
# Enter the macro text into the input field and
# press the button next to it to send it.
# use /n, /r, /t to send LF, CR, or TAB, respectively
# This example creates 2 buttons. You may add as many
# buttons as you like.
# Author: Roger Meier, 06-06-2020
# CoolTerm version: 1.7.0

import CoolTerm
import sys
import os
import tkinter

# --------------------------------------------------------
# CoolTerm Setup
# --------------------------------------------------------
s = CoolTerm.CoolTermSocket()

# Get the ID of the first open window
ID = s.GetWindowID(0)
if ID < 0:
    print("No open windows")

# Open the serial port
if not s.Connect(ID):
    print("Not Connected")
def send(txt):
    txt = txt.replace("\\n","\n") # replace "\n" with LF
    txt = txt.replace("\\r","\r") # replace "\r" with CR
    txt = txt.replace("\\t","\t") # replace "\t" with TAB
    s.Write(ID, txt)
# --------------------------------------------------------
# GUI Setup
# --------------------------------------------------------
w = tkinter.Tk()
w.title("CoolTerm Macros")

def send1():
txt1 = tkinter.Entry(w, width = 20)
txt1.grid(column=0, row=0)
btn1 = tkinter.Button(w, text = "Send", command = send1)
btn1.grid(column=1, row=0)

def send2():
txt2 = tkinter.Entry(w, width = 20)
txt2.grid(column=0, row=1)
btn2 = tkinter.Button(w, text = "Send", command = send2)
btn2.grid(column=1, row=1)

btnClose = tkinter.Button(w, text = "Close Window", command = w.destroy)

w.mainloop() # Code execution will stop here until w is closed

CoolTerm Macros.png
You do not have the required permissions to view the files attached to this post.
User avatar
Site Admin
Posts: 282
Joined: Fri Apr 24, 2009 12:41 am

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest