Skip to content

littlewhitecloud/TkTerminal

Repository files navigation

TkTerminal

PyPI Platform

TkTerminal is a terminal emulator written in Python using tkinter. It is quite easy to use.

Windows

MacOS

Features

  • User can set the terminal widget with their own options
  • Use \ to make new lines (On Windows it is &&)
  • Command history recorder
  • Styles
  • And some on

Future ideas

  • Highlight

Styles

tkterminalwidget also have some styles to use such as Powershell Command: image image But also, you can create your custom style by using

from tktermwidget import Config, POWERSHELL

styleconfig = Config(usetheme=True, basedon=POWERSHELL)
# if usetheme enable, the window will use sv_ttk theme
# basedon mean you can create your style based on the "basedon" style
styleconfig.mainloop()

image

After saving it, you can write down this to use the custom theme:

from tkinterwidget import Terminal, CUSTOM
example = Terminal(window, style=CUSTOM) # your custom theme
example.mainloop()

Or use a built in theme:

from tkinterwidget import Terminal, POWERSHELL # use powershell for an example
example = Terminal(window, style=POWERSHELL)
example.mainloop()

Installation:

pip install tktermwidget

Example:

from tkinter import Tk

from tkterm import Terminal

# Create root window
root = Tk()

# Hide root window during initialization
root.withdraw()

# Set title
root.title("Terminal")

# Create terminal
term = Terminal(root)
term.pack(expand=True, fill="both")

# Set minimum size and center app

# Update widgets so minimum size is accurate
root.update_idletasks()

# Get minimum size
minimum_width: int = root.winfo_reqwidth()
minimum_height: int = root.winfo_reqheight()

# Get center of screen based on minimum size
x_coords = int(root.winfo_screenwidth() / 2 - minimum_width / 2)
y_coords = int(root.wm_maxsize()[1] / 2 - minimum_height / 2)

# Place app and make the minimum size the actual minimum size (non-infringable)
root.geometry(f"{minimum_width}x{minimum_height}+{x_coords}+{y_coords}")
root.wm_minsize(minimum_width, minimum_height)

# Show root window
root.deiconify()

# Start mainloop
root.mainloop()