Function to close the window in Tkinter

Add parentheses after destroy to call the method. When you use command=self.root.destroy you pass the method to Tkinter.Button without the parentheses because you want Tkinter.Button to store the method for future calling, not to call it immediately when the button is created. But when you define the quit method, you need to call self.root.destroy() in … Read more

How do I create a popup window in tkinter?

I found 3 mistakes use Toplevel() instead of Tk() to create second/third window command= expects callback – function name without ()(but you use popupBonusWindow.destroy()) don’t mix pack() and grid() in one window or frame(but you use grid() and pack() in popup) But you can also use built-in messageboxes like showinfo() BTW: I put it on page: Tkinter: How to create popup Window or Messagebox

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 should be much, much … Read more

How to use an image for the background in tkinter?

One simple method is to use place to use an image as a background image. This is the type of thing that place is really good at doing. For example: You can then grid or pack other widgets in the parent as normal. Just make sure you create the background label first so it has a lower stacking order. Note: if you are … Read more

Install tkinter for Python

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 package manager … Read more

matplotlib error – no module named tkinter

For Linux Debian based distros: RPM based distros: 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 Anaconda or ActiveState. Test the python module p.s. I suggest … Read more

AttributeError: ” object has no attribute ”

Your NewsFeed class instance n doesn’t have a Canvas attribute. If you want to pass the Canvas defined in your Achtergrond class instance hoofdscherm to n, you can define it under the class definition for NewsFeed using __init__(): Then when you initialize your NewsFeed object as n, you can pass the Canvas instance from your Achtergrond class instance hoofdscherm: This is a solution to your current issue, but there are other errors in your code that you can see … Read more

Tkinter understanding mainloop

tk.mainloop() blocks. It means that execution of your Python commands halts there. You can see that by writing: You will never see the output from the print statement. Because there is no loop, the ball doesn’t move. On the other hand, the methods update_idletasks() and update() here: …do not block; after those methods finish, execution will continue, so the while loop will … Read more

Tkinter scrollbar for frame

“Am i doing it right?Is there better/smarter way to achieve the output this code gave me?” Generally speaking, yes, you’re doing it right. Tkinter has no native scrollable container other than the canvas. As you can see, it’s really not that difficult to set up. As your example shows, it only takes 5 or 6 … Read more