04 OCT 2019

Grid: Grid geometry manager puts the widgets in a 2-dimensional table. The master widget is split into a number of rows and columns, and each “cell” in the resulting table can hold a widget … full article

grid1.PNG

Entry validation: to restrict the characters that can be typed into an entry widget, only numbers for instance, a validate command can be added to the entry. A validate command is a function that return True if the change is accepted, False otherwise. This function will be called each time the content of the entry is modified full article

Radio button: the Radiobutton is a standard Tkinter widget used to implement one-of-many selections. Radiobuttons can contain text or images, and you can associate a Python function or method with each button. When the button is pressed, Tkinter automatically calls that function or method. The button can only display text in a single font, but the text may span more than one line. In addition, one of the characters can be underlined, for example to mark a keyboard shortcut. By default, the Tab key can be used to move to a button widget … full article

Listbox: the Listbox widget is a standard Tkinter widget used to display a list of alternatives. The listbox can only contain text items, and all items must have the same font and color. Depending on the widget configuration, the user can choose one or more alternatives from the list … full article

Bind: tkinter provides a powerful mechanism to let you deal with events yourself. For each widget, you can bind Python functions and methods to events … full article

widget.bind(event, handler)

Project II – file manager:

fileman2.png

click here to download the project

More topics covered:

  • Entry can use var such as StringVar 
  • Entry trick to notice text change
  • RadioButton set indicatoron=0
  • Listbox – selected items
  • Listbox – add remove
  • Listbox – mouse mouse

Links:

27 SEP 2019

Lambda functions: Python allows you to create anonymous function i.e function having no names using a facility called lambda function. lambda functions are small functions not more than a line. It can have any number of arguments just like a normal function. The body of lambda functions is very small and consists of only one expression. The result of the expression is the value when the lambda is applied to an argument. Also there is no need for any return statement in lambda function.

lambda1

filter1

map1

The Variable Classes (BooleanVar, DoubleVar, IntVar, StringVar)
You can ask the system to let you know when a variable is changed. The Tk toolkit can use this feature, called tracing, to update certain widgets when an associated variable is modified. or modify the value your self … full artice

More topics covered:

  • lambda with multiple arguments
  • lambda expression into tkinter
  • import time and time.ctime()
  • placing window widget on self

Links:

13 SEP 2019

At the class level, variables are referred to as class variables (static data), whereas variables at the instance level are called instance variables. When we expect variables are going to be consistent across instances, or when we would like to initialize a variable, we can define that variable at the class level. When we anticipate the variables will change significantly across instances, we can define them at the instance level. Defined outside of all the methods, class variables are, by convention, typically placed right below the class header and before the constructor method and other methods.

class_var.PNG

staticmethod (@staticmethod) is a method that knows nothing about the class or instance it was called on. It just gets the arguments that were passed, no implicit first argument. 

classmethod (@classmethod), is a method that gets passed the class it was called on, or the class of the instance it was called on, as first argument. This is useful when you want the method to be a factory for the class: since it gets the actual class it was called on as first argument, you can always instantiate the right class, even when subclasses are involved. Class methods are also used as an alternative constructors- for example from_string which creates as instance of the class from a string variable

TKinter: is the Python GUI toolkit. Tkinter is included with standard Linux, Microsoft Windows and Mac OS X installs of Python.

tkinter_code.PNG

tkinter.PNG

More topics covered:

  • static data
  • static – without self
  • static – fromlist
  • TKinter fonts
  • TKinter button styles
  • TKinter Implement a window class
  • mainloop – blocking method

Links: