Package: tkterminal
tkterminalThis library gives Terminal widget support to the Tkinter library. Perform almost all the operations of a terminal with tkterminal.InstallationUse the package manager pip to install with the following command:pipinstalltkterminalIf you would like to get the latest master or branch from GitHub, you could also:pipinstallgit+https://github.com/Saadmairaj/tkterminalOr even select a specific revision(branch/tag/commit):pipinstallgit+https://github.com/Saadmairaj/tkterminal@masterUsageTerminal widget is easy to use. Type the commands just like you type in the terminal.importtkinterastkfromtkterminalimportTerminalroot=tk.Tk()terminal=Terminal(pady=5,padx=5)terminal.pack(expand=True,fill='both')root.mainloop()Enable shell (shell=True)If the shell is True, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shellpipes,filename wildcards,environment variable expansion, andexpansion of ~ to a user’s home directory. However, note that Python itself offers implementations of many shell-like features (in particular,glob,fnmatch,os.walk(),os.path.expandvars(),os.path.expanduser(), andshutil).To have shell enabled terminal then set the shell to true like soterminal=Terminal()terminal.shell=TrueEnable line number bar for the terminal (linebar=True)If linebar is True, the terminal will have a line number bar on the left side which tells the number of the line by numbering each line of the terminal. Clicking on any number will select the specific line in the terminal. The line with the insert will be highlighted in the number bar.To have line number bar enabled terminal then set linebar to true like so.terminal=Terminal()terminal.linebar=TrueCommand that requires input.The tkterminal is using subprocess python module where the input can only be passed before running the command and cannot be passed after the command has ran. So the input can be pass with methods:Throughrun_command(cmd, give_input=None)method.Input can be passed directly to the parametergive_inputof run_command method along with the actual command.Example:importtkinterastkfromtkterminalimportTerminalroot=tk.Tk()terminal=Terminal(pady=5,padx=5)terminal.shell=Trueterminal.linebar=Trueterminal.pack(expand=True,fill='both')b1=tk.Button(root,text="Uninstall tkterminal",fg="Black",command=lambda:terminal.run_command('pip uninstall tkterminal','y'))b1.pack()root.mainloop()Directly typing into the Terminal window.We can directly pass input into the terminal after typing the command between these HTML tags<input> ... </input>these tags are just to read user input from the command.Example:pipuninstalltkterminal<input>y</input>DocumentationTerminal widget is created from the Tkinter Text widget class that makes it support all the options of a Text widget.Configurable options for a Terminal widget. Syntax:Terminal(root, options=value, ...)OptionsDescriptionbackgroundThe default background color of the terminal widget.borderwidthThe width of the border around the terminal widget. Default is 2 pixels.cursorThe cursor that will appear when the mouse is over the terminal widget.exportselectionNormally, text selected within a terminal widget is exported to be the selection in the window manager. Setexportselection=0if you don't want that behavior.fontThe default font for text inserted into the widget.foregroundThe color used for text within the widget. You can change the color for tagged regions; this option is just the default.heightThe height of the widget in lines (not pixels!), measured according to the current font size.highlightbackgroundThe color of the focus highlight when the terminal widget does not have focus.highlightcolorThe color of the focus highlight when the terminal widget has the focus.highlightthicknessThe thickness of the focus highlight. Default is 0.insertbackgroundThe color of the insertion cursor. Default is black.insertborderwidthSize of the 3-D border around the insertion cursor. Default is 0.insertofftimeThe number of milliseconds the insertion cursor is off during its blink cycle. Set this option to zero to suppress blinking. Default is 300.insertontimeThe number of milliseconds the insertion cursor is on during its blink cycle. Default is 600.insertwidthWidth of the insertion cursor (its height is determined by the tallest item in its line). Default is 2 pixels.padxThe size of the internal padding added to the left and right of the text area. Default is one pixel.padyThe size of the internal padding added above and below the text area. Default is one pixel.reliefThe 3-D appearance of the terminal widget. Default isrelief=SUNKEN.selectbackgroundThe background color to use displaying selected text.selectborderwidthThe width of the border to use around selected text.spacing1This option specifies how much extra vertical space to add between displayed lines of text when a logical line wraps. Default is 0.spacing2This option specifies how much extra vertical space to add between displayed lines of text when a logical line wraps. Default is 0.spacing3This option specifies how much extra vertical space is added below each line of text. If a line wraps, this space is added only after the last line it occupies on the display. Default is 0.stateNormally, terminal widgets respond to keyboard and mouse events; set state=NORMAL to get this behavior. If you set state=DISABLED, the terminal widget will not respond, and you won't be able to pass commands into the terminal.tabsThis option controls how tab characters position text.widthThe width of the widget in characters (not pixels!), measured according to the current font size.wrapThis option controls the display of lines that are too wide. Set wrap=WORD and it will break the line after the last word that will fit. With the default behavior,wrap=CHAR, any line that gets too long will be broken at any character.xscrollcommandTo make the terminal widget horizontally scrollable, set this option to theset()method of the horizontal scrollbar.yscrollcommandTo make the terminal widget vertically scrollable, set this option to theset()method of the vertical scrollbar.Methods onTerminalwidget objects:MethodsDescription.clear()Clears the console completely..get_output()Get the output of the recently run command. Returns None if no command has run else the function will return a dictionary of error and output..run_command(cmd, give_input=None)Run the command into the terminal..tag_config(tagname, option=value...)You can use this method to configure the tag properties, which include:--background-foreground-font-justify(center, left, or right),-tabs(this property has the same functionality of the Text widget tabs's property)-underline(used to underline the tagged text).Properties onTerminalwidget objects:PropertiesDescriptionterminal.basenameChange the basename of the terminal. Default istkterminal$terminal.linebarLine number bar tells the number of the line by numbering each line of the terminal. Clicking on any number will select the specific line in the terminal. The line with the insert will be highlighted in the number bar. Default is False.Configure output, error, basename and linebar:All output text have tag nameoutputwhich can be configured withterminal.tag_config("output", option=value...)method.All error text also have a tag nameerrorwhich can be configured withterminal.tag_config("error", option=value...)method.The basename also have a tag namebasenameconfigured withterminal.tag_config("basename", option=value...)method.The linebar is an object of Tkinter Canvas widget which can be configured withterminal.linebar.configure(option=value ...). And each number line is a canvas item whose tag name is the number itself that can be configured withterminal.linebar.itemconfigure('item', options...).