Ui (Version 3)

Some useful commands to make a UI using tkinter

from PythonFunctions.Ui import ui
tkUi = ui()

FontSettings

FontSettings(*, font, size)

Change the font and size of the ui elements

Parameters
  • font (str) – (Optional), The new font to use (Must be installed)

  • size (int) – (Optional), The new size of the font

tkUi.FontSettings(size=20)

CreateFrame

CreateFrame(row, column)

Creates a new tk Frame

Parameters
  • row (int) – (Optional). The row position. Defaults to 0

  • column (int) – (Optional). The column position. Defaults to 0

Returns

The frame created

Return type

tk.Frame

frame:tk.Frame = tkUi.CreateFrame()

CreateImage

CreateImage(filePath)

Creates a new tk PhotoImage object

Parameters

filePath (str) – The path of the image.

Returns

The PhotoImage object

Return type

tk.PhotoImage

AddButton

AddButton(text, callback, row, column, *, textVar, frame, sticky, callbackArgs, rowspan, columnspan, image)

Create a new tk button to interact with

Parameters
  • text (str) – The text to dispaly on the button

  • callback (function) – The function to call on button click

  • row (int) – (Optional) The row of the frame to put the button in. Defaults to 0

  • column (int) – (Optional) The column of the frame to put the button in. Defaults to 0

  • textVar (tk.StringVar) – (Optional) The text variable to use instead of text. Defaults to None

  • frame (tk.Frame) – (Optional) The frame to apply the button to. Defaults to None

  • sticky (str) – (Optional) The sides to stick to (“north”, “east”, “south”, “west”). Defaults to “nesw”

  • callbackArgs (any) – (Optional) value to send to the function on callback. Defaults to None

  • rowspan (int) – (Optional) How many rows does it take up. Defaults to 1

  • columnspan (int) – (Optional) How many columns does it take up. Defaults to 1

  • image – (Optional) The image to add onto the button. Defaults to None

Returns

The ui button element

Return type

tk.Button

button: tk.Button = tkUi.AddButton("Click me!", mycallback, 1, 1, frame=frame, callbackArgs="yes")

Note

This does not contain all of the tk.Button options, if you want something that isn’t here then use the actually tk.Button. If you want it added, file a pull request

AddLabel

AddLabel(text, row, column, *, textVar, frame, sticky, rowspan, columnspan, image)

Creates a new tk Label to interact with.

Parameters
  • text (str) – The text to display on the Label

  • row (int) – (Optional) The row of the frame to put the label in. Defaults to 0

  • column (int) – (Optional) The column of the frame to put the label in. Defaults to 0

  • textVar (tk.StringVar) – (Optional) The text variable to use instead of text. Defaults to None

  • frame (tk.Frame:) – (Optional) The frame to apply the label to. Defaults to None

  • sticky – (Optional) The sides to stick to (“north”, “east”, “south”, “west”)

  • rowspan (int) – (Optional) How many rows does it take up. Defaults to 1

  • columnspan (int) – (Optional) How many columns does it take up. Defaults to 1

  • image – (Optional) The image to display on the label. Defaults to None

Tyoe image

tk.PhotoImage

Returns

The label object

Return type

tk.Label

label: tk.Label = tkUi.AddLabel("", 0, 0, frame=frame)

Note

This does not contain all of the tk.Labal options, if you want something that isn’t here then use the actually tk.Button. If you want it added, file a pull request

AddTextBox

AddTextBox(textVar, row, column, *, frame, sticky, rowspan, columnspan, show)

Adds a text box to the UI which you can enter stuff into

Parameters
  • textVar (tk.StringVar) – The text variable to assign data to.

  • row (int) – (Optional) The row position of the label. Defaults to 0

  • column (int) – (Optional) The column position of the label. Defaults to 0

  • frame (tk.Frame) – (Optional) The frame to apply the label to. Defaults to None.

  • sticky (string) – (Optional) The sides to stick to (“north”, “east”, “south”, “west”)

  • rowspan (int) – (Optional) How many rows does it take up. Defaults to 1

  • columnspan (int) – (Optional) How many columns does it take up. Defaults to 1

  • show (str) – (Optional) The text to replace the input with. Defaults to “”

password = tk.StringVar()
textBox = tkUi.AddTextBox(password, show="*")

Note

show is a useful feature for hidding passwords

ChangeState

ChangeState(Element, state, *, row, column)

Show or hide an element

Parameters
  • Element (any (tk object)) – The element to effect

  • state (bool) – (Optional) The new mode of the element. Defaults to True.

  • row (int) – (Optional) The place to put the element. Defaults to 0.

  • column (int) – (Optional) The place to put the element. Defaults to 0.

tkUi.ChangeState(textBox, row=0, column=10) # set to true and places at (0, 10)
tkUi.ChangeState(textBox, False) # hides

Note

row and column are only needed it state is True

CreateStringVar

CreateStringVar(frame, default)

Creates a tk.StringVar variable

Parameters
  • frame (tk.StringVar) – The frame to attachs to. Defaults to self.canvas

  • default (str) – The default value to store in the variable

Returns

The object

Return type

tk.StringVar

pos = tkUi.CreateStringVar()