Update:
I've been learning to use a code generator called
PAGE by converting this CLI app of mine, into a GUI app, which I'm happy to share with you all.
The app needs two files:
File 1:
banner.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 7.6
# in conjunction with Tcl version 8.6
# May 12, 2023 12:27:46 AM BST platform: Linux
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import os.path
_script = sys.argv[0]
_location = os.path.dirname(_script)
import banner_support
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = 'gray40' # X11 color: #666666
_ana1color = '#c3c3c3' # Closest X11 color: 'gray76'
_ana2color = 'beige' # X11 color: #f5f5dc
_tabfg1 = 'black'
_tabfg2 = 'black'
_tabbg1 = 'grey75'
_tabbg2 = 'grey89'
_bgmode = 'light'
class bannerMain:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
top.geometry("650x325+359+232")
top.minsize(1, 1)
top.maxsize(1351, 738)
top.resizable(0, 0)
top.title("Banner Generator")
top.configure(highlightcolor="black")
top.configure(pady="5")
self.top = top
self.inputVar = tk.StringVar()
self.HScaleData = tk.DoubleVar()
self.labInput = tk.Label(self.top)
self.labInput.place(relx=0.083, rely=0.055, height=23, width=96)
self.labInput.configure(activebackground="#f9f9f9")
self.labInput.configure(anchor='w')
self.labInput.configure(compound='left')
self.labInput.configure(font="-family {DejaVu Sans} -size 12")
self.labInput.configure(text='''Input''')
self.bannerOut = tk.Text(self.top)
self.bannerOut.place(relx=0.085, rely=0.542, relheight=0.169
, relwidth=0.826)
self.bannerOut.configure(background="white")
self.bannerOut.configure(font="-family {DejaVu Sans Mono} -size 12")
self.bannerOut.configure(pady="12")
self.bannerOut.configure(selectbackground="#c4c4c4")
self.bannerOut.configure(wrap="word")
self.labOut = tk.Label(self.top)
self.labOut.place(relx=0.077, rely=0.437, height=23, width=72)
self.labOut.configure(activebackground="#f9f9f9")
self.labOut.configure(anchor='w')
self.labOut.configure(compound='left')
self.labOut.configure(font="-family {DejaVu Sans} -size 12")
self.labOut.configure(text='''Output''')
self.btnGenerate = tk.Button(self.top)
self.btnGenerate.place(relx=0.255, rely=0.769, height=33, width=73)
self.btnGenerate.configure(activebackground="beige")
self.btnGenerate.configure(borderwidth="2")
self.btnGenerate.configure(command=banner_support.on_btn_Gen)
self.btnGenerate.configure(compound='left')
self.btnGenerate.configure(text='''Generate''')
self.btnQuit = tk.Button(self.top)
self.btnQuit.place(relx=0.568, rely=0.769, height=33, width=73)
self.btnQuit.configure(activebackground="beige")
self.btnQuit.configure(borderwidth="2")
self.btnQuit.configure(command=banner_support.on_btn_Quit)
self.btnQuit.configure(compound='left')
self.btnQuit.configure(state='active')
self.btnQuit.configure(text='''Quit''')
self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
top.configure(menu = self.menubar)
self.bannerIn = tk.Entry(self.top)
self.bannerIn.place(relx=0.085, rely=0.123, height=50, relwidth=0.825)
self.bannerIn.configure(background="white")
self.bannerIn.configure(font="-family {DejaVu Sans Mono} -size 12")
self.bannerIn.configure(selectbackground="#c4c4c4")
self.bannerIn.configure(textvariable=self.inputVar)
self.HScale = tk.Scale(self.top, from_=20.0, to=50.0, resolution=1.0)
self.HScale.place(relx=0.206, rely=0.326, relheight=0.203
, relwidth=0.615)
self.HScale.configure(activebackground="beige")
self.HScale.configure(command=banner_support.on_HScale)
self.HScale.configure(label="Width")
self.HScale.configure(length="354")
self.HScale.configure(orient="horizontal")
self.HScale.configure(troughcolor="#d9d9d9")
self.HScale.configure(variable=self.HScaleData)
def start_up():
banner_support.main()
if __name__ == '__main__':
banner_support.main()
File 2:
banner_support.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 7.6
# in conjunction with Tcl version 8.6
# May 11, 2023 09:20:41 PM BST platform: Linux
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import banner
_debug = False # False to eliminate debug printing from callback functions.
def main(*args):
'''Main entry point for the application.'''
global root
root = tk.Tk()
root.protocol('WM_DELETE_WINDOW', root.destroy)
# Creates a toplevel widget.
global _top1, _w1
_top1 = root
_w1 = banner.bannerMain(_top1)
root.mainloop()
def banner_gen(**args):
if _debug:
print(f'banner_gen args: {args}')
if len(args['text']) > 0:
msg = args['text']
length = args['length']
else:
msg = "Remember: do one thing and do it well."
length = 50
if len(msg) % 2:
msg = "#" + f"<{msg}>".center(length, '=')
else:
msg = "#" + f"<{msg}>".center(length + 1, '=')
msg += "#"
return msg
def on_HScale(*args):
if _debug:
print('banner_support.on_HScale')
for arg in args:
print(' another arg:', arg)
sys.stdout.flush()
def on_btn_Gen(*args):
if _debug:
print('banner_support.on_btn_Gen')
for arg in args:
print(' another arg:', arg)
sys.stdout.flush()
valu = _w1.HScaleData.get()
text = _w1.inputVar.get()
print(f'_w1.inputVar.get(): {text}')
print(f'Len of _w1.inputVar.get(): {len(text)}')
BannerText = banner_gen(text=text, length=int(valu))
print(BannerText)
valu = _w1.HScaleData.get()
text = _w1.inputVar.get()
BannerText = banner_gen(text=text, length=int(valu)-1) # 'off-by-one' bug fix
_w1.bannerOut.delete('1.0', END)
_w1.bannerOut.insert('1.0', BannerText)
def on_btn_Quit(*args):
if _debug:
print('banner_support.on_btn_Quit')
for arg in args:
print(' another arg:', arg)
sys.stdout.flush()
root.destroy()
if __name__ == '__main__':
banner.start_up()
If you have any questions about this, then I'll answer them the best way that I can.
Thanks for reading.