From Tkinter Import From Tkinter Import TTK
From Tkinter Import From Tkinter Import TTK
first the root window should be created using Tk() command and then add the required widgets using
ttk module. for instance:
ttk.Button(),
ttk.Label()
You may modify each widget attributes by using the square brackets or using the config() function of
each widget.
+ You can use multiple geometry manager within an application but not with a single master.
The widgets that are interactive, the command attribute will be used to add the event handler and
meanwhile other widgets like labels which are less interactive you will use bind.
** For having a safe image import u need to store that image as reference to label or other widgets. You
may do in such matter:
Logo = PhotoImage(file=”image full path”)
Label.img = logo
Label.config(image = label.img)
** Tkinter variable classes are: 1. BooleanVar
2. DoubleVar
3. IntVar
4. StringVar
4.1. Functions:
+ set()
+ get()
3. Button
3.1. Attributes:
+ text
+ command: takes the function which does a certain task
+ font: format is font = (“Font type”, size, “bold/italic”)
+ image: adding an image to the label
+ compound: Controlling the display of text and image of the label.
- text, image, center, left
3.2. Functions:
+ invoke(): Simulates the pressing of the button
+ instate(): checking if the button is in which state and it returns True or False.
Format button.instate([“!disabled”/”disabled”])
+ state(): used to change the state of the button and used as follow:
Format button.state([“disabled”/”!disabled”])
Where, [“disabled”] will disable the button and [“!disabled”] will enable it.
4. Checkbutton
4.1. Attributes:
+ text
+ command
+ image
+ font
+ compound
+ variable: setting it to any tkinter variable classes
+ onvalue: setting the value if the box is checked/ticked
+ offvalue: setting the value if the box is not checked/ticked
+ textvariable: a variable for the text of check button
4.2. Functions:
+ invoke()
+ instate()
+ state()
5. Radiobutton
5.1. Attributes:
+ text
+ variable
+ value
6. Entry
6.1. Attributes:
+ width
+ show: replaces every character with anything character. Useful for password.
6.2. Functions:
+ get()
+ delete(idx_begin, id_end/END): to delete elements on entry based on indexes.
+ insert(idx_begin, “text”)
+ state(): used for changing the state of the entry and it has 2 states which are:
- “!disabled”/”disabled
- “!readonly”/”readonly”
+ instate()
7. Combobox
7.1. Attributes:
+ textvariable
+ values: which adds the lists of values to add as list.
8. Progressbar
8.1. Attributes:
+ orient: How it is going to be shown
Modes: HORIZONTAL, VERTICAL
+ length
+ mode: base on the load of the task
Modes: indeterminate, determinate
+ maximum: floating point for determinate mode
+ value: the value of progress which is a floating-point value
+ variable
8.2. Functions:
+ start()
+ stop()
+ step()
** start and stop functions are for indeterminate mode and meanwhile the step is for determinate
mode to increase the percentage of the progress bar.
9. Scale
9.1. Attributes:
+ orient
+ length
+ variable
+ from_
+ to
9.2. Functions:
+ set()
+ get()
10. Frame
10.1. Attributes:
+ height
+ width
+ padding: it takes a list of two value. (x, y)
+ relief: the look of the frame
Modes: 1. FLAT (default)
2. RAISED
3. SUNKEN
4. SOLID
5. RIDGE
6. GROOVE
11. LabelFrame
11.1. Attributes:
+ height
+ width
+ text
12. Panedwindow
12.1. Attributes:
+ orient: HORIZONTAL, VERTICAL
12.2. Function:
+ add(element, weight=”int value”)
+ insert(idx, element)
+ forget(idx): removes the element according to the index (the element is
hidden)
13. Notebook: creates Tabs
13.1. Function:
+ add(element, text=”str value”)
+ insert(idx, element, text=”str value”)
+ forget(idx)
+ select(): returns the ID of the selected tab by user by default
and it can select the tab by passing the index
+ index(element_ID): converts the ID number to the index of the tab
+ tab(idx, state=”str value”): changes the state of the tab.
3. Text
3.1. Attributes
+ width
+ height
+ wrap: wraps the text within the element and its takes string.
Modes: 1. Char (default)
2. none (will not wrap)
3. word (wraps around the last word)
+ state: disable/normal
3.2. function
+ get(“base-format”,”base-format”): it will get the content from specified place.
Base modifiers are usually: “line.char” and “end”. For instance“1.0” means line 1
and starting character with index 0.
+ insert(“line.char + # lines”, text): insert the a text
+ delete(“line.char”)
+ replace(“line.char”, text)