I’m trying to import Tkinter into Python using VS code
I’ve already used the from Tkinter import *
command but it seems to do nothing once I run it
Am I running it in the wrong place? Have I misspelt something? Are there more commands I need to run?
(I’m using Python 3.12.0 on Windows)
4
Answers
Have you tried installing the compatible version of VS code and Tkinter?
If so then please check whether the version of Tkinter is updated and also try to run the command on cmd if, it is running on the system then your Tkinter is fine else uninstall vs-code and re-install it.
It will work fine.
Here a few tips that can help you to fix your problem:
Try importing tkinter like this:
In Python 3.x, the
tkinter
module’s name starts with a lowercase letter, unlike in Python 2.x.Also, avoid using wildcard imports, as they can make code less readable and prone to conflicts. Instead, just import
tkinter
astk
and use thetk
prefix.A few things:
tkinter
, notTkinter
(these names are case-sensitive)from tkinter import *
won’t cause anything noticeable to happen. You’ve imported tkinter, but you haven’t done anything else with it.Here’s a very minimal example tkinter app that will pop up a window with some text on it
I recommend following some tkinter tutorials to get started and familiarize yourself with the basic widget classes and the typical structure of a tkinter app.