How do you run your own code alongside Tkinter’s event loop?

Use the after method on the Tk object: from tkinter import * root = Tk() def task(): print(“hello”) root.after(2000, task) # reschedule event in 2 seconds root.after(2000, task) root.mainloop() Here’s the declaration and documentation for the after method: def after(self, ms, func=None, *args): “””Call function once after given time. MS specifies the time in milliseconds. … Read more

How can I create a simple message box in Python?

You could use an import and single line code like this: import ctypes # An included library with Python install. ctypes.windll.user32.MessageBoxW(0, “Your text”, “Your title”, 1) Or define a function (Mbox) like so: import ctypes # An included library with Python install. def Mbox(title, text, style): return ctypes.windll.user32.MessageBoxW(0, text, title, style) Mbox(‘Your title’, ‘Your text’, … Read more

How do I handle the window close event in Tkinter?

Tkinter supports a mechanism called protocol handlers. Here, the term protocol refers to the interaction between the application and the window manager. The most commonly used protocol is called WM_DELETE_WINDOW, and is used to define what happens when the user explicitly closes a window using the window manager. You can use the protocol method to … Read more

How to update a plot in matplotlib

You essentially have two options: Do exactly what you’re currently doing, but call graph1.clear() and graph2.clear() before replotting the data. This is the slowest, but most simplest and most robust option. Instead of replotting, you can just update the data of the plot objects. You’ll need to make some changes in your code, but this … Read more

matplotlib error – no module named tkinter

For Linux Debian based distros: sudo apt-get install python3-tk RPM based distros: sudo yum install python3-tkinter For windows: For Windows, I think the problem is you didn’t install complete Python package. Since Tkinter should be shipped with Python out of box. See: http://www.tkdocs.com/tutorial/install.html . Good python distributions for Windows can be found by the companies … Read more

_tkinter.TclError: no display name and no $DISPLAY environment variable

Matplotlib chooses Xwindows backend by default. You need to set matplotlib to not use the Xwindows backend. Add this code to the start of your script (before importing pyplot) and try again: import matplotlib matplotlib.use(‘Agg’) Or add to .config/matplotlib/matplotlibrc line backend: Agg to use non-interactive backend. echo “backend: Agg” > ~/.config/matplotlib/matplotlibrc Or when connect to … Read more

Create a directly-executable cross-platform GUI app using Python

First you will need some GUI library with Python bindings and then (if you want) some program that will convert your python scripts into standalone executables. Cross-platform GUI libraries with Python bindings (Windows, Linux, Mac) Of course, there are many, but the most popular that I’ve seen in wild are: Tkinter – based on Tk … Read more

Install tkinter for Python [duplicate]

It is not very easy to install Tkinter locally to use with system-provided Python. You may build it from sources, but this is usually not the best idea with a binary package-based distro you’re apparently running. It’s safer to apt-get install python-tk on your machine(s). (Works on Debian-derived distributions like for Ubuntu; refer to your … Read more

ImportError: No module named ‘Tkinter’

You probably need to install it using something similar to the following: For Ubuntu or other distros with Apt: sudo apt-get install python3-tk For Fedora: sudo dnf install python3-tkinter You can also mention a Python version number like this: sudo apt-get install python3.7-tk sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64 Finally, import tkinter (for Python 3) or Tkinter … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)