Fix typos

This commit is contained in:
Marcello 2021-09-20 19:35:32 +02:00
parent 76550dfa3c
commit 5c0799df7f
118 changed files with 1150 additions and 1602 deletions

View file

@ -10,27 +10,27 @@ from tkinter import ttk # import Themed Widgets
## GEOMETRY MANAGEMENT
Putting widgets on screen
master widget --> toplevel window, frame
master widget --> top-level window, frame
slave widget --> widgets contained in master widget
geometry managers determine size and oder widget drawing properties
## EVENT HANDLING
event loop recives events from the OS
event loop receives events from the OS
customizable events provide a callback as a widget configuration
```py
widget.bind('event', function) # method to capture any event and than execute an arbitrary piece of code (generally a functio or lambda)
widget.bind('event', function) # method to capture any event and than execute an arbitrary piece of code (generally a function or lambda)
```
VIRTUAL EVENT --> hig level event genearted by widget (listed in widget docs)
VIRTUAL EVENT --> hig level event generated by widget (listed in widget docs)
## WIDGETS
"idgets are objects and all things on screen. All widgets are children of a window.
Widgets are objects and all things on screen. All widgets are children of a window.
```py
widget_name = tk_object(parent_window) # widget is insetred into widget hierarchy
widget_name = tk_object(parent_window) # widget is inserted into widget hierarchy
```
## FRAME WIDGET
@ -40,7 +40,7 @@ Displays a single rectangle, used as container for other widgets
```py
frame = ttk.Frame(parent, width=None, height=None, borderwidth=num:int)
# BORDERWIDTH: sets frame border width (default: 0)
# width, height MUST be specified if frame is empty, otherwise determinded by parent geometry manager
# width, height MUST be specified if frame is empty, otherwise determined by parent geometry manager
```
### FRAME PADDING
@ -49,7 +49,7 @@ Extra space inside widget (margin).
```py
frame['padding'] = num # same padding for every border
frame['padding'] = (horizzontal, vertical) # set horizontal THEN vertical padding
frame['padding'] = (horizontal, vertical) # set horizontal THEN vertical padding
frame['padding'] = (left, top, right, bottom) # set left, top, right, bottom padding
# RELIEF: set border style, [flat (default), raised, sunken, solid, ridge, groove]
@ -58,7 +58,7 @@ frame['relief'] = border_style
## LABEL WIDGET
Display tetx or image without interactivity.
Display text or image without interactivity.
```py
label = ttk.Label(parent, text='label text')
@ -67,7 +67,7 @@ label = ttk.Label(parent, text='label text')
### DEFINING UPDATING LABEL
```py
var = StringVar() # variable containing text, watchs for changes. Use get, set methods to interact with the value
var = StringVar() # variable containing text, watches for changes. Use get, set methods to interact with the value
label['textvariable'] = var # attach var to label (only of type StringVar)
var.set("new text label") # change label text
```
@ -105,7 +105,7 @@ label['anchor'] = compass_direction #compass_direction: n, ne, e, se, s, sw, w,
```py
# use \n for multi line text
label['wraplength'] = size # max line lenght
label['wraplength'] = size # max line length
```
### CONTROL TEXT JUSTIFICATION
@ -114,8 +114,8 @@ label['wraplength'] = size # max line lenght
label['justify'] = value #value: left, center, right
label['relief'] = label_style
label['foreground'] = color # color pased with name or HEX RGB codes
label['background'] = color # color pased with name or HEX RGB codes
label['foreground'] = color # color passed with name or HEX RGB codes
label['background'] = color # color passed with name or HEX RGB codes
```
### FONT STYLE (use with caution)
@ -129,7 +129,7 @@ Fonts:
- TkDefaultFont -- default for all GUI items
- TkTextFont -- used for entry widgets, listboxes, etc
- TkFixedFont -- standar fixed-width font
- TkFixedFont -- standard fixed-width font
- TkMenuFont -- used for menu items
- TkHeadingFont -- for column headings in lists and tables
- TkCaptionFont -- for window and dialog caption bars
@ -159,7 +159,7 @@ button.invoke() # button activation in the program
### BUTTON STATE
Activate (interagible) or deactivate (not interagible) the widget.
Activate or deactivate the widget.
```py
button.state(['disabled']) # set the disabled flag, disabling the button
@ -172,7 +172,7 @@ button.instate(['!disabled'], cmd) # execute 'cmd' if the button is not disable
## CHECKBUTTON
Button with binary value of some kind (e.g a toggle) and also invokes a comman callback
Button with binary value of some kind (e.g a toggle) and also invokes a command callback
```py
checkbutton_var = TkVarType
@ -182,9 +182,9 @@ check = ttk.Checkbutton(parent, text='button text', command=action_performed, va
### WIDGET VALUE
Variable option holds value of button, updated by widget toggle.
EFAULT: 1 (while checked), 0 (while unchecked)
`onvalue`, `offvalue` are used to personalize cheched and uncheched values
if linked variable is empry or different from on-offvalue the state flag is set to alternate
DEFAULT: 1 (while checked), 0 (while unchecked)
`onvalue`, `offvalue` are used to personalize checked and unchecked values
if linked variable is empty or different from on-off value the state flag is set to alternate
checkbutton won't set the linked variable (MUST be done in the program)
### CONFIG OPTIONS
@ -245,7 +245,7 @@ radio.instate(['flag'])
## COMBOBOX
Drop-down list of avaiable options.
Drop-down list of available options.
```py
combobox_var = StringVar()
@ -253,7 +253,7 @@ combo = ttk.Combobox(parent, textvariable=combobox_var)
combobox.get() # return combobox current value
combobox.set(value) # set combobox new value
combobox.current() # returns which item in the predefined values list is selected (0-based index of the provided list, -1 if not in the list)
#combobox will generate a bind-able <ComboxboSelected> virtual event whenever the value changes
#combobox will generate a bind-able <ComboboxSelected> virtual event whenever the value changes
combobox.bind('<<ComboboxSelected>>', function)
```
@ -271,7 +271,7 @@ Display list of single-line items, allows browsing and multiple selection (part
```py
lstbx = Listbox(parent, height=num, listvariable=item_list:list)
# listvariable links a variable (MUST BE a list) to the listbox, each elemenmt is a item of the listbox
# listvariable links a variable (MUST BE a list) to the listbox, each element is a item of the listbox
# manipulation of the list changes the listbox
```
@ -292,7 +292,7 @@ lstbx.curselection() # returns list of indices of selected items
scroll = ttk.Scrollbar(parent, orient=direction, command=widget.view)
# ORIENT: VERTICAL, HORIZONTAL
# WIDGET.VIEW: .xview, .yview
# NEEDS ASSOCITED WIDGET SCROLL CONFIG
# NEEDS ASSOCIATED WIDGET SCROLL CONFIG
widget.configure(xscrollcommand=scroll.set)
widget.configure(yscrollcommand=scroll.set)
```
@ -324,10 +324,10 @@ txt.delete(start, end) # delete range of text
Feedback about progress of lenghty operation.
```py
progbar = ttk.Progressbar(parent, orient=direction, lenght=num:int, value=num, maximum=num:float mode=mode)
progbar = ttk.Progressbar(parent, orient=direction, length=num:int, value=num, maximum=num:float mode=mode)
# DIRECTION: VERTICAL, HORIZONTAL
# MODE: determinate (relative progress of completion), indeterminate (no estimate of completion)
# LENGHT: dimension in pixel
# LENGTH: dimension in pixel
# VALUE: sets the progress, updates the bar as it changes
# MAXIMUM: total number of steps (DEFAULT: 100)
```
@ -342,7 +342,7 @@ progbar.step(amount) # increment value of given amount (DEFAULT: 1.0)
```py
progbar.start() # starts progressbar
progbar.stop() #stopos progressbar
progbar.stop() #stoops progressbar
```
## SCALE
@ -350,7 +350,7 @@ progbar.stop() #stopos progressbar
Provide a numeric value through direct manipulation.
```py
scale = ttk.Scale(parent, orient=DIR, lenght=num:int, from_=num:float, to=num:float, command=cmd)
scale = ttk.Scale(parent, orient=DIR, length=num:int, from_=num:float, to=num:float, command=cmd)
# COMMAND: calls cmd at every scale change, appends current value to func call
scale['value'] # set or read current value
scale.set(value) # set current value
@ -364,9 +364,9 @@ Choose numbers. The spinbox choses item from a list, arrows permit cycling lits
```py
spinval = StringVar()
spin = Spinbox(parent, from_=num, to=num, textvariable=spinval, increment=num, value=lst, wrap=boolean)
# INCREMENT specifies incremend\decremenment by arrow button
# INCREMENT specifies increment\decrement by arrow button
# VALUE: list of items associated with the spinbox
# WRAP: boolean value determining if value shuld wrap around if beyond start-end value
# WRAP: boolean value determining if value should wrap around if beyond start-end value
```
## GRID GEOMETRY MANAGER
@ -424,7 +424,7 @@ tlw = Toplevel(parent) # parent of root window, no need to grid it
window.destroy()
# can destroy every widget
# destroing parent also destroys it's children
# destroying parent also destroys it's children
```
### CHANGING BEHAVIOR AND STYLE
@ -436,7 +436,7 @@ window.title('new title') # sets title
# SIZE AND LOCATION
window.geometry(geo_specs)
'''full geomtry specification: width * height +- x +- y (actual coordinates of screen)
'''full geometry specification: width * height +- x +- y (actual coordinates of screen)
+x --> x pixels from left edge
-x --> x pixels from right edge
+y --> y pixels from top edge
@ -454,7 +454,7 @@ window.lift(otherwin) # relative to other window
window.lower() # absolute position
window.lower(otherwin) # relative to other window
# RESIZION BEHAVIOR
# RESIZE BEHAVIOR
window.resizable(boolean, boolean) # sets if resizable in width (1st param) and width (2nd param)
window.minsize(num, num) # sets min width and height
window.maxsize(num, num) # sets max width and height
@ -470,7 +470,7 @@ window.deiconify() # deiconifies window
### STANDARD DIALOGS
```py
# SLECTING FILE AND DIRECTORIES
# SLEETING FILE AND DIRECTORIES
# on Windows and Mac invokes underlying OS dialogs directly
from tkinter import filedialog
filename = filedialog.askopenfilename()