Windowed API

Tcl/Tk

Commands

wininit n

Initializes a window with the name n.

wintitle n ..t

Gives the window with name n the title ..t.

loopwin n

Loops the window with the name n.

closewin n

Closes the window with the name n.

btn ..j

Creates a button. ..j is some JSON that will configure the button. JSON keys:

  • name: The unique name you will use in your code to refer to the button.

  • parent: The parent window or frame.

  • text: The text on the button.

  • onclick: The code executed when the button is clicked.

sbtn ..j

Creates a styled button. ..j is some JSON that will configure the button. JSON keys:

  • name: The unique name you will use in your code to refer to the button.

  • parent: The parent window or frame.

  • text: The text on the button.

  • onclick: The code executed when the button is clicked.

lbl ..j

Creates a label. ..j is some JSON that will configure the label. JSON keys:

  • name: The unique name you will use in your code to refer to the label.

  • parent: The parent window or frame.

  • text: The text on the label.

txt ..j

Creates a text area. ..j is some JSON that will configure the text area. JSON keys:

  • name: The unique name you will use in your code to refer to the text.

  • parent: The parent window or frame.

  • width: The width of the text area.

  • height: The height of the text area.

scrolltxt ..j

Creates a text area with a scrollbar. ..j is some JSON that will configure the text area. JSON keys:

  • name: The unique name you will use in your code to refer to the text.

  • parent: The parent window or frame.

  • width: The width of the text area.

  • height: The height of the text area.

entry ..j

Creates a text box. ..j is some JSON that will help configure the text box. Required keys of ..j:

  • name: The name you will use in your code to refer to the text box.

  • parent: The parent window or frame.

sentry ..j

Creates a styled text box. ..j is some JSON that will help configure the text box. Required keys of ..j:

  • name: The name you will use in your code to refer to the text box.

  • parent: The parent window or frame.

modify ..j

Does something to a widget. ..j is some JSON. ..j keys:

  • name: The name of the widget which the something is to be done to.

  • args: The arguments for the something to be done. Can be anything, and can even be undefined (in some cases).

  • command: The something to be done. Can be:

    • “insert”: Inserts args[1] into an entry/sentry/txt/scrolltxt at position args[0]. In this case, args is an array.

    • “invoke”: Invokes a button. In this case, args does not need to be defined.

frm ..j

Creates a frame. ..j is some JSON that will help configure the frame. Required keys of ..j:

  • name: The name you will use in your code to refer to the frame.

  • parent: The parent window or frame.

info ..t | ..b

Opens an info message box with the title ..t and the body ..b.

askcolor

Opens a colour chooser popup and shows the colour the user entered in the CLI.

askopenfile

Opens a window that lets the user select a file.

askopenfiles

Opens a window that lets the user select many files.

dotcl n..t

Executes the Tcl code ..t on the window with the name n.

Variables

$tk_version

Gets the version of Tcl/Tk built in.

$tk_ext_version

Gets the extended version of Tcl/Tk built in.

Plotting

Commands

plot ..x * ..y

Plots a plot with x-axis ..x and y-axis ..y. Overloads -

  • plot ..x * ..ys

    Plots a plot with x-axis ..x and y-axis ..y. s is a Matplotlib format string for styling the plot.

bar ..l * ..n

Plots a vertical bar plot with labels ..l and values ..n. Overloads -

  • bar ..l * ..nc

    Plots a vertical bar plot with labels ..l and values ..n. c is the colour of all the bars.

barh ..l * ..n

Plots a horizontal bar plot with labels ..l and values ..n. Overloads -

  • barh ..l * ..nc

    Plots a horizontal bar plot with labels ..l and values ..n. c is the colour of all the bars.

pie ..l * ..n

Plots a pie with labels ..l and values ..n. Overloads -

  • pie ..l * ..n..c

    Plots a pie with labels ..l and values ..n. ..c is a list of the colour of the slices.

hist ..v

Plots a histogram with values ..v. Overloads -

  • hist random

    Plots a histogram with random values.

Turtle

Commands

forward px

Moves the turtle (the pen) forward by px pixels.

backward px

Moves it backward by px pixels.

left deg

Turns it left by deg degrees.

path.begin, path.start, pen.down

Starts drawing a line.

path.end, pen.up

Ends a line.

reset

Resets the turtle screen.

clear

Clears the screen.

color color

Sets the color of the current line to color.

fill color

Fills any fillable polygon that is drawn by the turtle with the color color.

fillcolor.start, fillcolor.begin

Starts filling any fillable polygon that is drawn by the turtle with the color specified by fill (see fill above).

fillcolor.end

Stops filling any fillable polygon that is drawn by the turtle with the color specified by fill (see fill above).

wait secs

Waits for secs seconds.

setx x

Sets the X coordinate of the turtle to x.

sety y

Sets the Y coordinate of the turtle to y.

stamp

Stamps a copy of the turtle onto the canvas.

stamps.clear

Clears all the stamps.

speed s

Sets the speed of the turtle to s.

size s

Sets the width of the line to s.

circle r

Makes the turtle draw a circle with radius r.

outline c

Sets the colour of the outline of the turtle to c.

hide

Hides the turtle.

show

Shows the turtle.

screen.color c

Sets the colour of the screen to c.

screen.image i

Sets the background image of the screen to i.

closeonclick

Makes it so that if you click the turtle window, it will close.

mode m

Sets the header mode to m. m can be -

  • “standard”: The default turtle heading is to the east

  • “world”: The default turtle heading is specified using user-defined world coordinates (using setworldcoordinates)

  • “logo”: The default turtle heading is to the north

goto x y

Makes the turtle go to x x and y y.

dot r c

Draws a dot with radius r and colour c.

shape s

Sets the shape of the turtle to s. s can be -

  • arrow

  • turtle

  • circle

  • square

  • triangle

  • classic

input ..t | ..b

Asks the user for input in the GUI. The window which appears has the title ..t and body ..b.

numinput ..t | ..b

Asks the user for a numerical input in the GUI. The window which appears has the title ..t and body ..b.

write ..t

Writes the string ..t on to the canvas.

screen.image ..i

Sets the background image of the screen to ..i.

Variables

$pos

Gets the position of the turtle.

$x

Gets the x coordinate (horizontal position) of the turtle.

$y

Gets the y coordinate (vertical position) of the turtle

$down

A boolean. True if the turtle is down, otherwise false. Toggleable using -

  • path.start, path.begin, pen.down

  • path.end, pen.up

$outline

Gets the color of the current outline of the turtle

$fill

Gets the color of the current filling of the turtle

$color

Gets the current color of the lines drawn by the turtle

$visible

Another boolean. True if the turtle is visible, otherwise false. Toggleable using -

  • hide

  • show

$turtle_shape_polygonal_points

The turtle’s current shape polygon as a list of coordinate pairs

$winwidth

The width of the window, in pixels

$winheight

The height of the window, in pixels

$bgimage

The current background image of the screen

$mode

The turtle heading mode of the drawing. Values -

  • “standard”: The default turtle heading is to the east

  • “world”: The default turtle heading is specified using user-defined world coordinates (using setworldcoordinates)

  • “logo”: The default turtle heading is to the north

Toggleable using -

  • mode

$shape

Gets the current shape of the turtle.