Questions tagged [tkinter]
Tkinter is the standard Python interface to the "tcl/tk" graphical user interface toolkit. In Python 3, the name of the module changed from Tkinter to tkinter.
tkinter
52,490
questions
448
votes
27
answers
1.1m
views
ImportError: No module named 'Tkinter' [duplicate]
For some reason, I can't use the Tkinter (or tkinter, on Python 3) module.
After running the following command in the python shell:
import Tkinter
or this, in Python 3:
import tkinter
I got this ...
349
votes
24
answers
923k
views
Install tkinter for Python [duplicate]
I am trying to import Tkinter. However, I get an error stating that Tkinter has not been installed:
ImportError: No module named _tkinter, please install the python-tk package
I could probably ...
312
votes
14
answers
229k
views
Create a directly-executable cross-platform GUI app using Python
Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.
The problem ...
275
votes
14
answers
487k
views
How to pass arguments to a Button command in Tkinter?
Suppose I have the following Button made with Tkinter in Python:
import Tkinter as Tk
win = Tk.Toplevel()
frame = Tk.Frame(master=win).grid(row=1, column=1)
button = Tk.Button(master=frame, text='...
247
votes
10
answers
464k
views
_tkinter.TclError: no display name and no $DISPLAY environment variable
I am running a simple python script in the server:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(60)
y = np.random.randn(60)
plt.scatter(x, y, s=20)
out_png = 'path/to/...
226
votes
19
answers
304k
views
matplotlib error - no module named tkinter [duplicate]
I tried to use the matplotlib package via Pycharm IDE on windows 10.
when I run this code:
from matplotlib import pyplot
I get the following error:
ImportError: No module named 'tkinter'
I know ...
220
votes
8
answers
633k
views
How to update a plot in matplotlib
I'm having issues with redrawing the figure here. I allow the user to specify the units in the time scale (x-axis) and then I recalculate and call this function plots(). I want the plot to simply ...
219
votes
9
answers
280k
views
What is the best way to structure a Tkinter application? [closed]
The following is the overall structure of my typical Python Tkinter program.
def funA():
def funA1():
def funA12():
# stuff
def funA2():
# stuff
def funB():
...
207
votes
11
answers
293k
views
How do I handle the window close event in Tkinter?
How do I handle the window close event (user clicking the 'X' button) in a Python Tkinter program?
177
votes
18
answers
536k
views
How can I create a simple message box in Python?
I'm looking for the same effect as alert() in JavaScript.
I wrote a simple web-based interpreter this afternoon using Twisted Web. You basically submit a block of Python code through a form, and the ...
173
votes
22
answers
302k
views
Tkinter: "Python may not be configured for Tk" [duplicate]
Today I wanted to start working with Tkinter, but I have some problems.
Python 3.2 (r32:88445, Mar 28 2011, 04:14:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more ...
163
votes
9
answers
383k
views
How to get the input from the Tkinter Text Widget?
How to get Tkinter input from the Text widget?
EDIT
I asked this question to help others with the same problem - that is the reason why there is no example code. This issue had been troubling me for ...
161
votes
6
answers
228k
views
How do you run your own code alongside Tkinter's event loop?
My little brother is just getting into programming, and for his Science Fair project, he's doing a simulation of a flock of birds in the sky. He's gotten most of his code written, and it works nicely, ...
151
votes
4
answers
319k
views
Dynamically updating plot in matplotlib
I am making an application in Python which collects data from a serial port and plots a graph of the collected data against arrival time. The time of arrival for the data is uncertain. I want the plot ...
140
votes
14
answers
917k
views
How to pip or easy_install tkinter on Windows [duplicate]
IDLE is throwing errors that and says tkinter can't be imported.
Is there a simple way to install tkinter via pip or easy_install?
There seem to be a lot of package names flying around for this...
...
134
votes
17
answers
473k
views
How do I close a tkinter window?
How do I end a Tkinter program? Let's say I have this code:
from Tkinter import *
def quit():
# code to exit
root = Tk()
Button(root, text="Quit", command=quit).pack()
root.mainloop()
How ...
131
votes
4
answers
264k
views
Switch between two frames in tkinter?
I have built my first few scripts with a nice little GUI on them, as the tutorials have shown me, but none of them address what to do for a more complex program.
If you have something with a 'start ...
127
votes
3
answers
237k
views
Adding padding to a tkinter widget only on one side
How can I add padding to a tkinter window, without tkinter centering the widget?
I tried:
self.canvas_l = Label(self.master, text="choose a color:", font="helvetica 12")
self.canvas_l.grid(row=9, ...
125
votes
4
answers
307k
views
Understanding lambda in Python and using it to pass multiple arguments
After reading everything I can find on lambda expressions in Python, I still don't understand how to make it do what I want.
Everyone uses the example:
lambda x, y : x + y
Why do you need to state ...
117
votes
20
answers
976k
views
PermissionError: [Errno 13] Permission denied
I'm getting this error :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File &...
116
votes
11
answers
118k
views
Interactively validating Entry widget content in tkinter
What is the recommended technique for interactively validating content in a tkinter Entry widget?
I've read the posts about using validate=True and validatecommand=command, and it appears that these ...
108
votes
5
answers
43k
views
Why is my Button's command executed immediately when I create the Button, and not when I click it? [duplicate]
My code is:
from Tkinter import *
admin = Tk()
def button(an):
print(an)
print('het')
b = Button(admin, text='as', command=button('hey'))
b.pack()
mainloop()
The button doesn't work, it ...
107
votes
3
answers
302k
views
Tkinter understanding mainloop
Till now, I used to end my Tkinter programs with: tk.mainloop(), or nothing would show up! See example:
from Tkinter import *
import random
import time
tk = Tk()
tk.title = "Game"
tk....
100
votes
15
answers
234k
views
Tkinter module not found on Ubuntu
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
on the other ...
99
votes
3
answers
100k
views
Adding a scrollbar to a group of widgets in Tkinter
I am using Python to parse entries from a log file, and display the entry contents using Tkinter and so far it's been excellent. The output is a grid of label widgets, but sometimes there are more ...
98
votes
8
answers
147k
views
How can I schedule updates (f/e, to update a clock) in tkinter?
I'm writing a program with Python's tkinter library.
My major problem is that I don't know how to create a timer or a clock like hh:mm:ss.
I need it to update itself (that's what I don't know how to ...
95
votes
15
answers
220k
views
How to center a window on the screen in Tkinter?
I'm trying to center a tkinter window. I know I can programatically get the size of the window and the size of the screen and use that to set the geometry, but I'm wondering if there's a simpler way ...
95
votes
13
answers
175k
views
Is there a way to make the Tkinter text widget read only?
It doesn't look like it has that attribute, but it'd be really useful to me.
95
votes
8
answers
204k
views
Tkinter scrollbar for frame
My objective is to add a vertical scroll bar to a frame which has several labels in it. The scroll bar should automatically enabled as soon as the labels inside the frame exceed the height of the ...
91
votes
5
answers
98k
views
Why does Tkinter image not show up if created in a function?
This code works:
import tkinter
root = tkinter.Tk()
canvas = tkinter.Canvas(root)
canvas.grid(row = 0, column = 0)
photo = tkinter.PhotoImage(file = './test.gif')
canvas.create_image(0, 0, image=...
90
votes
9
answers
144k
views
How do I get an event callback when a Tkinter Entry widget is modified?
Exactly as the question says. Text widgets have the <<Modified>> event, but Entry widgets don't appear to.
90
votes
8
answers
118k
views
How do I get rid of Python Tkinter root window?
Do you know a smart way to hide or in any other way get rid of the root window that appears, opened by Tk()? I would like just to use a normal dialog.
Should I skip the dialog and put all my ...
88
votes
4
answers
145k
views
Why do I get "AttributeError: NoneType object has no attribute" using Tkinter? Where did the None value come from?
I've created this simple GUI:
from tkinter import *
root = Tk()
def grabText(event):
print(entryBox.get())
entryBox = Entry(root, width=60).grid(row=2, column=1, sticky=W)
grabBtn = Button(...
88
votes
4
answers
156k
views
List of All Tkinter Events
In Python tkinter module, <Button-1>, <Button-2> and <Button-3> are used to identify mouse button clicks for left, middle and right buttons respectively.
Likewise, <KeyPress-...
84
votes
11
answers
296k
views
Using Tkinter in python to edit the title bar
I am trying to add a custom title to a window but I am having troubles with it. I know my code isn't right but when I run it, it creates 2 windows instead, one with just the title tk and another ...
84
votes
6
answers
74k
views
What is the difference between the widgets of tkinter and tkinter.ttk in Python?
The main tkinter module and its submodule ttk in Python 3 appear to contain identical widgets (i.e. Buttons, CheckButtons, etc.).
So, when creating a button, one has the freedom to either use a ...
82
votes
12
answers
119k
views
How to make a Tkinter window jump to the front?
How do I get a Tkinter application to jump to the front? Currently, the window appears behind all my other windows and doesn't get focus.
Is there some method I should be calling?
81
votes
2
answers
93k
views
Equivalent function for xticks for an AxesSubplot object
So I am trying to use Axes objects to control my matlibplot figure. I am not using plt (aka import matlibplot.pyplot as plt) because I am embedding the figure in my tkinter GUI per this.
However, I ...
79
votes
11
answers
78k
views
How do I display tooltips in Tkinter?
Tooltips are those little bits of text that popup when the mouse hovers over a widget for a certain duration of time.
How can I add a tooltip message to my tkinter Python application?
79
votes
10
answers
253k
views
How to clear/delete the contents of a Tkinter Text widget?
I am writing a Python program in TKinter on Ubuntu to import and print
the name of files from particular folder in Text widget.
It is just adding filenames to the previous filnames in the Text
widget, ...
79
votes
5
answers
134k
views
Tkinter: How to use threads to preventing main event loop from "freezing"
I have a small GUI test with a "Start" button and a Progress bar. The desired behavior is:
Click Start
Progressbar oscillates for 5 seconds
Progressbar stops
The observed behavior is the "Start" ...
78
votes
3
answers
144k
views
Difference between "fill" and "expand" options for tkinter pack method
What's the difference between the "fill" and "expand" options for Tkinter's pack method?
I have actually looked up about it everywhere, and I am unable to find the satisfactory ...
74
votes
7
answers
147k
views
How to specify where a Tkinter window opens?
How can I tell a Tkinter window where to open, based on screen dimensions? I would like it to open in the middle.
74
votes
3
answers
127k
views
How to update the image of a Tkinter Label widget?
I would like to be able to swap out an image on a Tkinter label, but I'm not sure how to do it, except for replacing the widget itself.
Currently, I can display an image like so:
import Tkinter as ...
72
votes
6
answers
199k
views
How can I prevent a window from being resized with tkinter?
I have a program which creates a window where a message is displayed according to a check box.
How can I make the window size constant when the message is displayed and the message is not displayed?
...
71
votes
12
answers
81k
views
tkinter: binding mousewheel to scrollbar
I have this scroll-able frame (frame inside canvas actually).
import Tkinter as tk
class Scrollbarframe():
def __init__(self, parent,xsize,ysize,xcod,ycod):
def ScrollAll(event):
...
71
votes
6
answers
32k
views
Unable to install tkinter with pyenv Pythons on MacOS
Versions of Python installed via pyenv fail to import tkinter:
※ python
Python 3.8.1 (default, Feb 29 2020, 11:45:59)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" ...
71
votes
3
answers
235k
views
How to select a directory and store the location using tkinter in Python
I am creating a GUI with a browse button which I only want to return the path. I've been looking at solutions using code like below.
Tkinter.Button(subframe, text = "Browse", command = self....
71
votes
10
answers
69k
views
Why does Python installed via Homebrew not include Tkinter [duplicate]
I've installed Python via Homebrew on my Mac.
brew install python
After that I checked my Python version as 2.7.11, then I tried to perform
import Tkinter
I got following error message:
Traceback (...
71
votes
2
answers
169k
views
How to set default text for a Tkinter Entry widget
How do I set the default text for a Tkinter Entry widget in the constructor? I checked the documentation, but I do not see a something like a "string=" option to set in the constructor?
There is a ...