Detecting Changes in the File System in Real Time with Watchdog

/images/detecting-changes-in-the-file-system-in-real-time-with-watchdog/watchdog-tk-python.gif

(The source code for this program is at the bottom.)

Watchdog is a cross-platform Python library that allows you to monitor file system events in real time. It is very useful for automating tasks if we want our program to execute an operation when a file is modified, deleted, moved, etc. Let's see how it works by creating a simple program that logs events for files in a folder.

Read more…

Installing and Using pip on Windows, Linux and macOS

pip is a tool written in Python to facilitate the download and installation of packages hosted in the Python Package Index (PyPI). It runs on all major platforms: Microsoft Windows, Linux and macOS; CPython 2.6+, 3.x and PyPy.

Before using pip, make sure it is installed. Open the terminal and run:

$ python -m pip --version

Windows users might also use:

> py -m pip --version

If you get no error, then jump directly to the last section to learn how to use this tool to download, install and upgrade packages. Otherwise continue reading.

Read more…

Message Box in Tk (tkinter)

A message box is a window with a title, a message, an icon, and one or more buttons. It is used to inform the user about something or encourage him to take an action.

The functions for creating message boxes in a Tcl/Tk application are defined within the tkinter.messagebox standard module (tkMessageBox in Python 2), and are the following:

  • showinfo()

  • showwarning()

  • showerror()

  • askquestion()

  • askyesno()

  • askokcancel()

  • askyesnocancel()

  • askretrycancel()

Read more…

Button in Tk (tkinter)

The button is typically the most common widget in a GUI application. A button is a box with a text and/or an image that can be pressed by the user to execute an operation. In Tk it is represented by the tk.Button and ttk.Button (which has a modern style) classes. From the point of view of the code its use is quite simple.

Like any other Tk widget, to get a button we must create an instance of the proper class:

import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.config(width=300, height=200)
root.title("Button in Tk")
button = ttk.Button(text="Hello world!")
button.place(x=50, y=50)
root.mainloop()

Read more…