Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter module not showing output

Tags:

python

tkinter

I am trying to learn Python and trying something GUI in Python and came across this Tkinter module. My code runs but the window does not appear when I run. My code is as follows:

from Tkinter import *
#to create a root window 
root = Tk()

The program runs, gives no errors but the window does not show up.

like image 704
mkumars Avatar asked Oct 25 '12 01:10

mkumars


People also ask

Why tkinter is not working in Python?

The easiest way to fix this problem is by upgrading your python to use python 3. If upgrading python is not an option, you only need to rename your imports to use Tkinter (uppercase) instead of tkinter (lowercase). Output: As a result, this window proves that your python installation includes the Tkinter module.

Why does it say no module named tkinter?

The Python "ModuleNotFoundError: No module named 'tkinter'" occurs when tkinter is not installed in our Python environment. To solve the error, install the module and import is as import tkinter as tk .


1 Answers

Add this to your code root.mainloop(), Here's a tutorial.

In response to your comment

#Also note that `from <module> import *` is generally frowned upon
#since it can lead to namespace collisions. It's much better to only
#explicitly import the things you need.
from Tkinter import Tk, Label
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
like image 159
John Avatar answered Sep 20 '22 08:09

John